<?php declare(strict_types=1);
namespace Acris\Rrp;
use Doctrine\DBAL\Connection;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Uuid\Uuid;
class AcrisRrpCS extends Plugin
{
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
$this->cleanupDatabase();
}
public function activate(ActivateContext $context): void
{
$this->insertDefaultDownloadTab($context->getContext());
}
private function cleanupDatabase(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_rule');
$connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_price_translation');
$connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_price');
$connection->executeStatement('ALTER TABLE `rule` DROP COLUMN `acrisRrps`');
}
private function insertDefaultDownloadTab(Context $context): void
{
$downloadTabRepository = $this->container->get('acris_rrp_price.repository');
/** @var IdSearchResult $IdSearchResult */
$IdSearchResult = $downloadTabRepository->searchIds((new Criteria()), $context);
if($IdSearchResult->getTotal() == 0) {
$downloadTabRepository->create($this->getDefaultDownloadTabData(), $context);
}
}
private function getDefaultDownloadTabData(): array
{
return [
[
'priority' => 10,
'active' => true,
'displayTax' => 'gross',
'boxDisplay' => false,
'detailDisplay' => true,
'translations' => [
'en-GB' => [
'internalName' => "ACRIS_RRP_Rule_Demo",
'boxGrossTextBefore' => "RRP: ",
'boxNetTextBefore' => "RRP: ",
'boxGrossTextAfter' => "incl. VAT.",
'boxNetTextAfter' => "excl. VAT.",
'detailGrossTextBefore' => "RRP: ",
'detailNetTextBefore' => "RRP: ",
'detailGrossTextAfter' => "incl. VAT.",
'detailNetTextAfter' => "excl. VAT."
],
'de-DE' => [
'internalName' => "ACRIS_RRP_Rule_Demo",
'boxGrossTextBefore' => "UVP:",
'boxNetTextBefore' => "UVP: ",
'boxGrossTextAfter' => "inkl. MwSt.",
'boxNetTextAfter' => "exkl. MwSt.",
'detailGrossTextBefore' => "UVP: ",
'detailNetTextBefore' => "UVP: ",
'detailGrossTextAfter' => "inkl. MwSt.",
'detailNetTextAfter' => "exkl. MwSt."
],
[
'languageId' => Defaults::LANGUAGE_SYSTEM,
'internalName' => "ACRIS_RRP_Rule_Demo",
'boxGrossTextBefore' => "RRP: ",
'boxNetTextBefore' => "RRP: ",
'boxGrossTextAfter' => "incl. VAT.",
'boxNetTextAfter' => "excl. VAT.",
'detailGrossTextBefore' => "RRP: ",
'detailNetTextBefore' => "RRP: ",
'detailGrossTextAfter' => "incl. VAT.",
'detailNetTextAfter' => "excl. VAT."
]
]
]
];
}
}