custom/plugins/DmitsInquirySales/src/DmitsInquirySales.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Dmits\InquirySales;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\Framework\CustomField\CustomFieldTypes;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
  14. use Shopware\Core\System\SystemConfig\SystemConfigDefinition;
  15. use Doctrine\DBAL\Connection;
  16. use Shopware\Core\Framework\Uuid\Uuid;
  17. use Shopware\Core\Defaults;
  18. use Composer\InstalledVersions;
  19. use Dmits\InquirySales\CustomFields\CustomFieldUpdater;
  20. class DmitsInquirySales extends Plugin
  21. {
  22.     
  23.     private function getCustomFieldUpdater()
  24.     {
  25.         /**
  26.          * @var EntityRepositoryInterface $customFieldSetRepository
  27.          */
  28.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  29.         
  30.         /**
  31.          * @var EntityRepositoryInterface $customFieldRepository
  32.          */
  33.         $customFieldRepository $this->container->get('custom_field.repository');
  34.         
  35.         return new CustomFieldUpdater(
  36.             $customFieldSetRepository,
  37.             $customFieldRepository,
  38.             $this->path
  39.             );
  40.     }
  41.     
  42.     public function getViewPaths(): array
  43.     {
  44.         $viewPaths parent::getViewPaths();
  45.         $viewPaths[] = 'Resources/views/storefront';
  46.         return $viewPaths;
  47.     }
  48.     
  49.     public function activate(ActivateContext $context): void
  50.     {
  51.         $this->getCustomFieldUpdater()->sync();
  52.         parent::activate($context);
  53.     }
  54.     
  55.     public function deactivate(DeactivateContext $context): void
  56.     {
  57.         $shopwareContext $context->getContext();
  58.         parent::deactivate($context);
  59.     }
  60.     
  61.     public function install(InstallContext $context): void
  62.     {
  63.         parent::install($context);
  64.         $this->getCustomFieldUpdater()->sync();
  65.     }
  66.     
  67.     public function uninstall(UninstallContext $context): void
  68.     {
  69.         parent::uninstall($context);
  70.         
  71.         
  72.         $shopwareVersion InstalledVersions::getVersion('shopware/core');
  73.         if ($context->keepUserData())
  74.             return;
  75.         
  76.         $this->getCustomFieldUpdater()->remove();
  77.         try{
  78.             $connection $this->container->get(Connection::class);
  79.             if (version_compare($shopwareVersion'6.4''>=')) {
  80.                 $connection->exec('DROP TABLE IF EXISTS `dmits_inquirysales_distributions`');
  81.                 $connection->exec('DROP TABLE IF EXISTS `dmits_inquirysales_requests`');
  82.             }else{
  83.                 $connection->executeQuery('DROP TABLE IF EXISTS `dmits_inquirysales_distributions`');
  84.                 $connection->executeQuery('DROP TABLE IF EXISTS `dmits_inquirysales_requests`');
  85.             }
  86.             
  87.             
  88.             
  89.             
  90.         }
  91.         catch(\Exception $e){
  92.             
  93.         }
  94.         
  95.         
  96.     }
  97.     
  98. }