<?php declare(strict_types=1);namespace Swpa\SwpaSort;use Doctrine\DBAL\Connection;use Shopware\Core\Framework\Plugin;use Shopware\Core\Framework\Plugin\Context\ActivateContext;use Shopware\Core\Framework\Plugin\Context\DeactivateContext;use Shopware\Core\Framework\Plugin\Context\InstallContext;use Shopware\Core\Framework\Plugin\Context\UninstallContext;use Shopware\Core\System\SystemConfig\SystemConfigService;use Swpa\SwpaSort\Setup;use Symfony\Component\Config\FileLocator;use Symfony\Component\DependencyInjection\ContainerBuilder;use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;use Symfony\Component\DependencyInjection\Reference;//require_once __DIR__ . '/../vendor/autoload.php';/** * Main class of the plugin SwpaSort: * * @package Swpa\SwpaSort * @license See COPYING.txt for license details * @author swpa <info@swpa.dev> */class SwpaSort extends Plugin{ /** * @param ContainerBuilder $container * * @throws \Exception */ public function build(ContainerBuilder $container): void { $yamlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/DI/config')); $yamlLoader->load('commands.yml'); $yamlLoader->load('controllers.yml'); $yamlLoader->load('services.yml'); $yamlLoader->load('subscribers.yml'); $this->initSorting($container); parent::build($container); } /** * @param ContainerBuilder $container */ private function initSorting(ContainerBuilder $container) { $sortingServices = $container->findTaggedServiceIds('swpa.sort.sorting'); $categoryProductService = $container->getDefinition('Swpa\SwpaSort\Service\CategoryProductService'); foreach ($sortingServices as $id => $attributes) { $categoryProductService->addMethodCall('addSortingService', [new Reference($id)]); } } /** * @return string */ public function getStorefrontScriptPath(): string { return 'Resources/dist/storefront/js'; } /** * @param InstallContext $context */ public function install(InstallContext $context): void { $install = new Setup\Install($this->container->get(Connection::class)); $install->install($context); parent::install($context); } /** * @param UninstallContext $context */ public function uninstall(UninstallContext $context): void { $install = new Setup\Uninstall($this->container->get(Connection::class)); $install->uninstall($context); parent::uninstall($context); } /** * @param ActivateContext $context */ public function activate(ActivateContext $context): void { $install = new Setup\Activate( $this->container->get(Connection::class), $this->container->get(SystemConfigService::class) ); $install->activate($context); parent::activate($context); } /** * @param DeactivateContext $context */ public function deactivate(DeactivateContext $context): void { $install = new Setup\Deactivate($this->container->get(Connection::class)); $install->deactivate($context); parent::deactivate($context); }}