custom/plugins/MndCookie/src/Subscriber/Frontend.php line 34

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MndCookie\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\Content\Cms\Events\CmsPageLoadedEvent;
  6. use Psr\Container\ContainerInterface;
  7. use Doctrine\DBAL\Connection;
  8. class Frontend implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var SystemConfigService
  12.      */
  13.     private $systemConfigService;
  14.     /** @var ContainerInterface  */
  15.     private $container;
  16.     public function __construct(SystemConfigService $systemConfigServiceContainerInterface $container)
  17.     {
  18.         $this->systemConfigService $systemConfigService;
  19.         $this->container $container;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             CmsPageLoadedEvent::class => 'onPageLoad'
  25.         ];
  26.     }
  27.     public function onPageLoad(CmsPageLoadedEvent $event): void
  28.     {
  29.         $result $event->getResult();
  30.         $pageIds $result->getIds();
  31.         $mndConfigType $this->systemConfigService->get('MndCookie.config.type');
  32.         $mndConfigPagesAccess $this->systemConfigService->get('MndCookie.config.cmsPagesAccess');
  33.         $isAccessPage false;
  34.         // Check if MndFacebookPixelTracking is active
  35.         $connection $this->container->get(Connection::class);
  36.         $pixelActive $connection->executeQuery('SELECT name FROM plugin WHERE name="MndFacebookPixelTracking" AND active=1')->fetch();
  37.         if($pixelActive !== false) {
  38.             $this->systemConfigService->set('MndCookie.config.fpIsActive'true);
  39.         } else {
  40.             $this->systemConfigService->set('MndCookie.config.fpIsActive'false);
  41.         }
  42.         // Check if access page
  43.         if($pageIds && $mndConfigPagesAccess) {
  44.             foreach($pageIds as $pageId) {
  45.                 if(in_array($pageId$mndConfigPagesAccess)) {
  46.                     $isAccessPage true;
  47.                 }
  48.             }
  49.         }
  50.         $this->systemConfigService->set('MndCookie.config.isAccessPage'$isAccessPage);
  51.     }
  52. }