custom/plugins/AcrisRrpCS/src/AcrisRrpCS.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\Rrp;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
  8. use Shopware\Core\Framework\Plugin;
  9. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Shopware\Core\Framework\Uuid\Uuid;
  12. class AcrisRrpCS extends Plugin
  13. {
  14.     public function uninstall(UninstallContext $uninstallContext): void
  15.     {
  16.         if ($uninstallContext->keepUserData()) {
  17.             return;
  18.         }
  19.         $this->cleanupDatabase();
  20.     }
  21.     public function activate(ActivateContext $context): void
  22.     {
  23.         $this->insertDefaultDownloadTab($context->getContext());
  24.     }
  25.     private function cleanupDatabase(): void
  26.     {
  27.         $connection $this->container->get(Connection::class);
  28.         $connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_rule');
  29.         $connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_price_translation');
  30.         $connection->executeStatement('DROP TABLE IF EXISTS acris_rrp_price');
  31.         $connection->executeStatement('ALTER TABLE `rule` DROP COLUMN `acrisRrps`');
  32.     }
  33.     private function insertDefaultDownloadTab(Context $context): void
  34.     {
  35.         $downloadTabRepository $this->container->get('acris_rrp_price.repository');
  36.         /** @var IdSearchResult $IdSearchResult */
  37.         $IdSearchResult $downloadTabRepository->searchIds((new Criteria()), $context);
  38.         if($IdSearchResult->getTotal() == 0) {
  39.             $downloadTabRepository->create($this->getDefaultDownloadTabData(), $context);
  40.         }
  41.     }
  42.     private function getDefaultDownloadTabData(): array
  43.     {
  44.         return [
  45.             [
  46.                 'priority' => 10,
  47.                 'active' => true,
  48.                 'displayTax' => 'gross',
  49.                 'boxDisplay' => false,
  50.                 'detailDisplay' => true,
  51.                 'translations' => [
  52.                     'en-GB' => [
  53.                         'internalName' => "ACRIS_RRP_Rule_Demo",
  54.                         'boxGrossTextBefore' => "RRP: ",
  55.                         'boxNetTextBefore' => "RRP: ",
  56.                         'boxGrossTextAfter' => "incl. VAT.",
  57.                         'boxNetTextAfter' => "excl. VAT.",
  58.                         'detailGrossTextBefore' => "RRP: ",
  59.                         'detailNetTextBefore' => "RRP: ",
  60.                         'detailGrossTextAfter' => "incl. VAT.",
  61.                         'detailNetTextAfter' => "excl. VAT."
  62.                     ],
  63.                     'de-DE' => [
  64.                         'internalName' => "ACRIS_RRP_Rule_Demo",
  65.                         'boxGrossTextBefore' => "UVP:",
  66.                         'boxNetTextBefore' => "UVP: ",
  67.                         'boxGrossTextAfter' => "inkl. MwSt.",
  68.                         'boxNetTextAfter' => "exkl. MwSt.",
  69.                         'detailGrossTextBefore' => "UVP: ",
  70.                         'detailNetTextBefore' => "UVP: ",
  71.                         'detailGrossTextAfter' => "inkl. MwSt.",
  72.                         'detailNetTextAfter' => "exkl. MwSt."
  73.                     ],
  74.                     [
  75.                         'languageId' => Defaults::LANGUAGE_SYSTEM,
  76.                         'internalName' => "ACRIS_RRP_Rule_Demo",
  77.                         'boxGrossTextBefore' => "RRP: ",
  78.                         'boxNetTextBefore' => "RRP: ",
  79.                         'boxGrossTextAfter' => "incl. VAT.",
  80.                         'boxNetTextAfter' => "excl. VAT.",
  81.                         'detailGrossTextBefore' => "RRP: ",
  82.                         'detailNetTextBefore' => "RRP: ",
  83.                         'detailGrossTextAfter' => "incl. VAT.",
  84.                         'detailNetTextAfter' => "excl. VAT."
  85.                     ]
  86.                 ]
  87.             ]
  88.         ];
  89.     }
  90. }