custom/plugins/EasyCreditRatenkauf/src/EasyCreditRatenkauf.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Netzkollektiv\EasyCredit;
  9. if (\file_exists(__DIR__ '/../vendor/autoload.php')) {
  10.     require_once __DIR__ '/../vendor/autoload.php';
  11. }
  12. use Netzkollektiv\EasyCredit\Util\Lifecycle\ActivateDeactivate;
  13. use Netzkollektiv\EasyCredit\Util\Lifecycle\InstallUninstall;
  14. use Shopware\Core\Framework\Plugin;
  15. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  16. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  17. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  18. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  19. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  20. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  21. use Shopware\Core\System\SystemConfig\SystemConfigService;
  22. use Symfony\Component\Config\FileLocator;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  25. use Netzkollektiv\EasyCredit\Compatibility\EntityCompilerPass;
  26. use Netzkollektiv\EasyCredit\Compatibility\Capabilities;
  27. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  28. use Symfony\Component\Config\Loader\DelegatingLoader;
  29. use Symfony\Component\Config\Loader\LoaderResolver;
  30. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  31. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  32. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  33. use Symfony\Contracts\Service\Attribute\Required;
  34. class EasyCreditRatenkauf extends Plugin
  35. {
  36.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_EASYCREDIT_TRANSACTION_ID 'easycredit_transaction_id';
  37.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_EASYCREDIT_TECHNICAL_TRANSACTION_ID 'easycredit_technical_transaction_id';
  38.     /**
  39.      * @var ActivateDeactivate
  40.      */
  41.     protected $activateDeactivate;
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function build(ContainerBuilder $container): void
  46.     {
  47.         parent::build($container);
  48.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  49.         $loader->load('compatibility.xml');
  50.         $loader->load('easycredit_payment.xml');
  51.         if ((new Capabilities($container->getParameter('kernel.shopware_version')))->hasFlowBuilder()) {
  52.             $loader->load('flow.xml');
  53.         }
  54.         $loader->load('setting.xml');
  55.         $loader->load('rule.xml');
  56.         $container->addCompilerPass(new EntityCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION500);
  57.         $this->loadPackagesConfig($container);
  58.     }
  59.     protected function loadPackagesConfig($container)
  60.     {
  61.         $locator = new FileLocator('Resources/config');
  62.         $resolver = new LoaderResolver([
  63.             new YamlFileLoader($container$locator),
  64.             new GlobFileLoader($container$locator),
  65.             new DirectoryLoader($container$locator),
  66.         ]);
  67.         $configLoader = new DelegatingLoader($resolver);
  68.         $confDir \rtrim($this->getPath(), '/') . '/Resources/config';
  69.         $configLoader->load($confDir '/{packages}/*.yaml''glob');
  70.     }
  71.     public function install(InstallContext $installContext): void
  72.     {
  73.         (new InstallUninstall(
  74.             $this->container->get('system_config.repository'),
  75.             $this->container->get('payment_method.repository'),
  76.             $this->container->get('country.repository'),
  77.             $this->container->get('currency.repository'),
  78.             $this->container->get(PluginIdProvider::class),
  79.             $this->container->get(SystemConfigService::class),
  80.             static::class
  81.         ))->install($installContext);
  82.         parent::install($installContext);
  83.     }
  84.     public function uninstall(UninstallContext $uninstallContext): void
  85.     {
  86.         if ($uninstallContext->keepUserData()) {
  87.             parent::uninstall($uninstallContext);
  88.             return;
  89.         }
  90.         (new InstallUninstall(
  91.             $this->container->get('system_config.repository'),
  92.             $this->container->get('payment_method.repository'),
  93.             $this->container->get('country.repository'),
  94.             $this->container->get('currency.repository'),
  95.             $this->container->get(PluginIdProvider::class),
  96.             $this->container->get(SystemConfigService::class),
  97.             static::class
  98.         ))->uninstall($uninstallContext);
  99.         parent::uninstall($uninstallContext);
  100.     }
  101.     public function update(UpdateContext $updateContext): void
  102.     {
  103.         (new InstallUninstall(
  104.             $this->container->get('system_config.repository'),
  105.             $this->container->get('payment_method.repository'),
  106.             $this->container->get('country.repository'),
  107.             $this->container->get('currency.repository'),
  108.             $this->container->get(PluginIdProvider::class),
  109.             $this->container->get(SystemConfigService::class),
  110.             static::class
  111.         ))->update($updateContext);
  112.         parent::update($updateContext);
  113.     }
  114.     /**
  115.      * @Required
  116.      */
  117.     #[Required]
  118.     public function setActivateDeactivate(ActivateDeactivate $activateDeactivate): void
  119.     {
  120.         $this->activateDeactivate $activateDeactivate;
  121.     }
  122.     public function activate(ActivateContext $activateContext): void
  123.     {
  124.         parent::activate($activateContext);
  125.         $this->activateDeactivate->activate($activateContext->getContext());
  126.     }
  127.     public function deactivate(DeactivateContext $deactivateContext): void
  128.     {
  129.         parent::deactivate($deactivateContext);
  130.         $this->activateDeactivate->deactivate($deactivateContext->getContext());
  131.     }
  132. }