custom/plugins/WvPopups/src/Subscriber/WvPopupsSubscriber.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace WvPopups\Subscriber;
  3. use DateTime;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Core\Framework\Struct\ArrayEntity;
  8. class WvPopupsSubscriber implements EventSubscriberInterface
  9. {
  10.     private SystemConfigService $systemConfigService;
  11.   
  12.     public function __construct(SystemConfigService $systemConfigService)
  13.     {
  14.         $this->systemConfigService $systemConfigService;
  15.     }
  16.       
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             GenericPageLoadedEvent::class => 'onPageLoaded',
  21.         ];
  22.     }
  23.     public function onPageLoaded(GenericPageLoadedEvent $event): void
  24.     {
  25.         $plugin_config = array();
  26.         
  27.         
  28.         $voucherActive $this->systemConfigService->get('WvPopups.config.voucherActive');
  29.         if($this->systemConfigService->get('WvPopups.config.voucherActiveUntil') != ''){
  30.           $voucherActiveUntil = new DateTime($this->systemConfigService->get('WvPopups.config.voucherActiveUntil'));
  31.           $now = new DateTime();
  32.           if($now $voucherActiveUntil){
  33.             $voucherActive false;
  34.           }
  35.         }
  36.         
  37.         $plugin_config['voucherMedia'] = $this->systemConfigService->get('WvPopups.config.voucherMedia');
  38.         $plugin_config['voucherTitle'] = $this->systemConfigService->get('WvPopups.config.voucherTitle');
  39.         $plugin_config['voucherContent'] = $this->systemConfigService->get('WvPopups.config.voucherContent');
  40.         $plugin_config['voucherActive'] = $voucherActive;
  41.         $plugin_config['voucherActiveUntil'] = $this->systemConfigService->get('WvPopups.config.voucherActiveUntil');
  42.         $plugin_config['voucherCode'] = $this->systemConfigService->get('WvPopups.config.voucherCode');
  43.         $plugin_config['voucherLink'] = $this->systemConfigService->get('WvPopups.config.voucherLink');
  44.         $plugin_config['voucherLinkTitle'] = $this->systemConfigService->get('WvPopups.config.voucherLinkTitle');
  45.         $plugin_config['voucherButtonFirst'] = $this->systemConfigService->get('WvPopups.config.voucherButtonFirst');
  46.         
  47.         $plugin_config['voucherBannerTitle'] = $this->systemConfigService->get('WvPopups.config.voucherBannerTitle');
  48.         
  49.         
  50.         $exitActive $this->systemConfigService->get('WvPopups.config.exitActive');
  51.         if($this->systemConfigService->get('WvPopups.config.exitActiveUntil') != ''){
  52.           $exitActiveUntil = new DateTime($this->systemConfigService->get('WvPopups.config.exitActiveUntil'));
  53.           $now = new DateTime();
  54.           if($now $exitActiveUntil){
  55.             $exitActive false;
  56.           }
  57.         }
  58.         $plugin_config['exitMedia'] = $this->systemConfigService->get('WvPopups.config.exitMedia');
  59.         $plugin_config['exitTitle'] = $this->systemConfigService->get('WvPopups.config.exitTitle');
  60.         $plugin_config['exitContent'] = $this->systemConfigService->get('WvPopups.config.exitContent');
  61.         $plugin_config['exitActive'] = $exitActive;
  62.         $plugin_config['exitActiveUntil'] = $this->systemConfigService->get('WvPopups.config.exitActiveUntil');
  63.         $plugin_config['exitCode'] = $this->systemConfigService->get('WvPopups.config.exitCode');
  64.         $plugin_config['exitLink'] = $this->systemConfigService->get('WvPopups.config.exitLink');
  65.         $plugin_config['exitLinkTitle'] = $this->systemConfigService->get('WvPopups.config.exitLinkTitle');
  66.         $plugin_config['exitButtonFirst'] = $this->systemConfigService->get('WvPopups.config.exitButtonFirst');
  67.         
  68.         
  69.         //add the array to the page as an extension
  70.         $event->getPage()->addExtension('wvPopupsExtension', new ArrayEntity($plugin_config));
  71.     }
  72. }