custom/plugins/EconsorBundles/src/EconsorBundles.php line 18

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EconsorBundles;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\System\CustomField\CustomFieldTypes;
  10. use Symfony\Component\Config\FileLocator;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  13. class EconsorBundles extends Plugin
  14. {
  15.     /**
  16.      * @param ContainerBuilder $container
  17.      * @inheritDoc
  18.      * @throws \Exception
  19.      */
  20.     public function build(ContainerBuilder $container): void
  21.     {
  22.         parent::build($container);
  23.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  24.         $loader->load('controller.xml');
  25.     }
  26.     public function install(InstallContext $installContext): void
  27.     {
  28.         parent::install($installContext);
  29.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  30.         $bundles $customFieldSetRepository->searchIds((new Criteria())->addFilter(new EqualsFilter('name''Bundle Step')), $installContext->getContext())->getIds();
  31.         if (empty($bundles)) {
  32.             $customFieldSetRepository->upsert(
  33.                 [
  34.                     [
  35.                         'name' => 'Bundle Step',
  36.                         'customFields' => [
  37.                             ['name' => 'step_1''type' => CustomFieldTypes::BOOL'config' => [
  38.                                 'type' => 'checkbox',
  39.                                 'label' => 'Step 1',
  40.                                 'customFieldPosition' => '1',
  41.                                 'customFieldType' => 'checkbox'
  42.                             ]
  43.                             ],
  44.                             ['name' => 'step_2''type' => CustomFieldTypes::BOOL'config' => [
  45.                                 'type' => 'checkbox',
  46.                                 'label' => 'Step 2',
  47.                                 'customFieldPosition' => '2',
  48.                                 'customFieldType' => 'checkbox'
  49.                             ]
  50.                             ],
  51.                             ['name' => 'step_3''type' => CustomFieldTypes::BOOL'config' => [
  52.                                 'type' => 'checkbox',
  53.                                 'label' => 'Step 3',
  54.                                 'customFieldPosition' => '3',
  55.                                 'customFieldType' => 'checkbox'
  56.                             ]
  57.                             ],
  58.                         ],
  59.                         'relations' => [
  60.                             [
  61.                                 'entityName' => 'product'
  62.                             ]
  63.                         ]
  64.                     ]
  65.                 ], $installContext->getContext());
  66.         }
  67.     }
  68.     public function uninstall(UninstallContext $uninstallContext): void
  69.     {
  70.         parent::uninstall($uninstallContext);
  71.         $connection $this->container->get(Connection::class);
  72.         $customFieldSetId $connection->fetchAll('SELECT LOWER(HEX(`id`)) AS id FROM `custom_field_set` WHERE `name` = "Bundle Step"');
  73.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  74.         if (isset($customFieldSetId[0])) {
  75.             $customFieldSetRepository->delete(
  76.                 [
  77.                     [
  78.                         'id' => $customFieldSetId[0]['id']
  79.                     ]
  80.                 ],
  81.                 $uninstallContext->getContext()
  82.             );
  83.         }
  84.         $this->removeMigrations();
  85.         $connection->executeQuery('DROP TABLE IF EXISTS `ec_bundles_translation`');
  86.         $connection->executeQuery('DROP TABLE IF EXISTS `ec_bundles_product`');
  87.         $connection->executeQuery('DROP TABLE IF EXISTS `ec_bundles`');
  88.         $connection->executeQuery('DROP TABLE IF EXISTS `ec_collection`');
  89.     }
  90. }