custom/plugins/CfCookieFirst/src/Subscriber/PageSubscriber.php line 45

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cf\CookieFirst\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\System\SystemConfig\SystemConfigService;
  5. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  6. use Cf\CookieFirst\Struct\StorefrontPageData;
  7. /**
  8.  * Class PageSubscriber
  9.  *
  10.  * @package Cf\CookieFirst\Subscriber
  11.  */
  12. class PageSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var SystemConfigService
  16.      */
  17.     private $systemConfigService;
  18.     /**
  19.      * PageSubscriber constructor.
  20.      * @param SystemConfigService $systemConfigService
  21.      */
  22.     public function __construct(SystemConfigService $systemConfigService)
  23.     {
  24.         $this->systemConfigService $systemConfigService;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             FooterPageletLoadedEvent::class => 'onFooterLoaded',
  33.         ];
  34.     }
  35.     /**
  36.      * @param FooterPageletLoadedEvent $event
  37.      */
  38.     public function onFooterLoaded(FooterPageletLoadedEvent $event): void
  39.     {
  40.         if (!$this->systemConfigService->get(
  41.             'CookieFirst.config.showWidget'$event->getSalesChannelContext()->getSalesChannel()->getId()
  42.         )) {
  43.             return;
  44.         }
  45.         $config $this->systemConfigService->getDomain('CookieFirst.config'$event->getSalesChannelContext()->getSalesChannel()->getId(), true );
  46.         $configValues = new StorefrontPageData($config);
  47.         $event->getPagelet()->addExtension('CookieFirst'$configValues);
  48.     }
  49. }