custom/plugins/SwpaSort/src/SwpaSort.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swpa\SwpaSort;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  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\System\SystemConfig\SystemConfigService;
  10. use Swpa\SwpaSort\Setup;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. //require_once __DIR__ . '/../vendor/autoload.php';
  16. /**
  17.  * Main class of the plugin SwpaSort:
  18.  *
  19.  * @package Swpa\SwpaSort
  20.  * @license See COPYING.txt for license details
  21.  * @author  swpa <info@swpa.dev>
  22.  */
  23. class SwpaSort extends Plugin
  24. {
  25.     /**
  26.      * @param ContainerBuilder $container
  27.      *
  28.      * @throws \Exception
  29.      */
  30.     public function build(ContainerBuilder $container): void
  31.     {
  32.         $yamlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ '/DI/config'));
  33.         $yamlLoader->load('commands.yml');
  34.         $yamlLoader->load('controllers.yml');
  35.         $yamlLoader->load('services.yml');
  36.         $yamlLoader->load('subscribers.yml');
  37.         $this->initSorting($container);
  38.         parent::build($container);
  39.     }
  40.     /**
  41.      * @param ContainerBuilder $container
  42.      */
  43.     private function initSorting(ContainerBuilder $container)
  44.     {
  45.         $sortingServices $container->findTaggedServiceIds('swpa.sort.sorting');
  46.         $categoryProductService $container->getDefinition('Swpa\SwpaSort\Service\CategoryProductService');
  47.         foreach ($sortingServices as $id => $attributes) {
  48.             $categoryProductService->addMethodCall('addSortingService', [new Reference($id)]);
  49.         }
  50.     }
  51.     /**
  52.      * @return string
  53.      */
  54.     public function getStorefrontScriptPath(): string
  55.     {
  56.         return 'Resources/dist/storefront/js';
  57.     }
  58.     /**
  59.      * @param InstallContext $context
  60.      */
  61.     public function install(InstallContext $context): void
  62.     {
  63.         $install = new Setup\Install($this->container->get(Connection::class));
  64.         $install->install($context);
  65.         parent::install($context);
  66.     }
  67.     /**
  68.      * @param UninstallContext $context
  69.      */
  70.     public function uninstall(UninstallContext $context): void
  71.     {
  72.         $install = new Setup\Uninstall($this->container->get(Connection::class));
  73.         $install->uninstall($context);
  74.         parent::uninstall($context);
  75.     }
  76.     /**
  77.      * @param ActivateContext $context
  78.      */
  79.     public function activate(ActivateContext $context): void
  80.     {
  81.         $install = new Setup\Activate(
  82.             $this->container->get(Connection::class),
  83.             $this->container->get(SystemConfigService::class)
  84.         );
  85.         $install->activate($context);
  86.         parent::activate($context);
  87.     }
  88.     /**
  89.      * @param DeactivateContext $context
  90.      */
  91.     public function deactivate(DeactivateContext $context): void
  92.     {
  93.         $install = new Setup\Deactivate($this->container->get(Connection::class));
  94.         $install->deactivate($context);
  95.         parent::deactivate($context);
  96.     }
  97. }