custom/plugins/MolliePayments/src/Subscriber/StorefrontBuildSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. namespace Kiener\MolliePayments\Subscriber;
  3. use Kiener\MolliePayments\Compatibility\VersionCompare;
  4. use Kiener\MolliePayments\Service\SettingsService;
  5. use Shopware\Storefront\Event\StorefrontRenderEvent;
  6. use Shopware\Storefront\Theme\StorefrontPluginConfiguration\StorefrontPluginConfiguration;
  7. use Shopware\Storefront\Theme\StorefrontPluginRegistryInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class StorefrontBuildSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var SettingsService
  13.      */
  14.     private $settingsService;
  15.     /**
  16.      * @var StorefrontPluginRegistryInterface
  17.      */
  18.     private $pluginRegistry;
  19.     /**
  20.      * @var VersionCompare
  21.      */
  22.     private $versionCompare;
  23.     /**
  24.      * @param SettingsService $settingsService
  25.      * @param StorefrontPluginRegistryInterface $pluginRegistry
  26.      * @param VersionCompare $versionCompare
  27.      */
  28.     public function __construct(SettingsService $settingsServiceStorefrontPluginRegistryInterface $pluginRegistryVersionCompare $versionCompare)
  29.     {
  30.         $this->settingsService $settingsService;
  31.         $this->pluginRegistry $pluginRegistry;
  32.         $this->versionCompare $versionCompare;
  33.     }
  34.     /**
  35.      * @inheritDoc
  36.      */
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [
  40.             StorefrontRenderEvent::class => 'onStorefrontRender',
  41.         ];
  42.     }
  43.     /**
  44.      * @param StorefrontRenderEvent $event
  45.      * @throws \Exception
  46.      * @return void
  47.      */
  48.     public function onStorefrontRender(StorefrontRenderEvent $event): void
  49.     {
  50.         $settings $this->settingsService->getSettings($event->getSalesChannelContext()->getSalesChannel()->getId());
  51.         $useJsValue = (int)$settings->isUseShopwareJavascript();
  52.         $event->setParameter('mollie_javascript_use_shopware'$useJsValue);
  53.         $mollieJavascriptAlreadyExists false;
  54.         if ($this->versionCompare->gte('6.6')) {
  55.             $plugin $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments');
  56.             if ($plugin instanceof StorefrontPluginConfiguration) {
  57.                 $scriptFiles $plugin->getScriptFiles();
  58.                 if ($useJsValue === 0) {
  59.                     $scriptFiles->remove(0);
  60.                 }
  61.                 $mollieJavascriptAlreadyExists $scriptFiles->count() > 0;
  62.             }
  63.         }
  64.         $event->setParameter('mollie_javascript_already_exists'$mollieJavascriptAlreadyExists);
  65.     }
  66. }