custom/plugins/Serkiz6Housenumber/src/Subscriber/TemplateSubscriber.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Serkiz6Housenumber\Subscriber;
  3. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  4. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  5. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  6. use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoadedEvent;
  7. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  8. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  9. use Shopware\Core\System\SystemConfig\SystemConfigService;
  10. use Shopware\Core\Content\Product\ProductEvents;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  15. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  16. class TemplateSubscriber implements EventSubscriberInterface
  17. {
  18.     const CONFIG_NAMESPACE 'Serkiz6Housenumber';
  19.     private $activatedCountries null;
  20.     private $container;
  21.     private $context;
  22.     private $systemConfigService;
  23.   
  24.     public function __construct($container,$systemConfigService)
  25.     {
  26.       $this->container $container;
  27.       $this->systemConfigService $systemConfigService;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             HeaderPageletLoadedEvent::class => 'onHeaderPageletLoaded'
  33.         ];
  34.     }
  35.     /**
  36.      * @param AccountPaymentMethodPageLoadedEvent|HeaderPageletLoadedEvent|CheckoutConfirmPageLoadedEvent $event
  37.      */
  38.     public function onHeaderPageletLoaded($event): void
  39.     {
  40.         try {
  41.             if($event instanceof HeaderPageletLoadedEvent){
  42.                 $pluginConfig $this->systemConfigService->getDomain(self::CONFIG_NAMESPACE);
  43.                 if($pluginConfig){
  44.                     $context $event->getSalesChannelContext();
  45.                     $struct = new SerkizConfigStruct($pluginConfig,$context);
  46.                     $event->getPagelet()->addExtension(self::CONFIG_NAMESPACE$struct);
  47.                 }
  48.             }
  49.         }catch (\Exception $e) {
  50.             return;
  51.         }
  52.     }
  53. }