custom/static-plugins/IronMatomo/src/Subscriber/MatomoSettingsSubscriber.php line 49

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace IronMatomo\Subscriber;
  3. use IronMatomo\Matomo\MatomoDataService;
  4. use Shopware\Storefront\Event\StorefrontRenderEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. /**
  7.  * Class MatomoSettingsSubscriber
  8.  *
  9.  * @package IronMatomo\Subscriber
  10.  */
  11. class MatomoSettingsSubscriber implements EventSubscriberInterface
  12. {
  13.     const MATOMO_DATA_EXTENSION_ID 'ironMatomoData';
  14.     /**
  15.      * @var MatomoDataService
  16.      */
  17.     private $matomoDataService;
  18.     /**
  19.      * MatomoSettingsSubscriber constructor.
  20.      *
  21.      * @param MatomoDataService $matomoDataService
  22.      */
  23.     public function __construct(
  24.         MatomoDataService $matomoDataService
  25.     )
  26.     {
  27.         $this->matomoDataService $matomoDataService;
  28.     }
  29.     /*
  30.      * @inherit
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             StorefrontRenderEvent::class => 'onStorefrontRender',
  36.         ];
  37.     }
  38.     /**
  39.      * @param StorefrontRenderEvent $event
  40.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  41.      */
  42.     public function onStorefrontRender(StorefrontRenderEvent $event)
  43.     {
  44.         if ($event->getRequest()->isXmlHttpRequest()) {
  45.             return;
  46.         }
  47.         $parameters $event->getParameters();
  48.         if (isset($parameters['page'])) {
  49.             $matomoData $this->matomoDataService->getMatomoData($event->getSalesChannelContext());
  50.             $page $parameters['page'];
  51.             $page->addExtensions([self::MATOMO_DATA_EXTENSION_ID => $matomoData]);
  52.         }
  53.     }
  54. }