custom/plugins/PremsIndividualOffer6/src/Subscriber/PageLoadedSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. /**
  3.  * PremSoft
  4.  * Copyright © 2021 Premsoft - Sven Mittreiter
  5.  *
  6.  * @copyright  Copyright (c) 2021, premsoft - Sven Mittreiter (http://www.premsoft.de)
  7.  * @author     Sven Mittreiter <info@premsoft.de>
  8.  */
  9. namespace Prems\Plugin\PremsIndividualOffer6\Subscriber;
  10. use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\OfferService;
  11. use Shopware\Core\Framework\Struct\ArrayStruct;
  12. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class PageLoadedSubscriber implements EventSubscriberInterface
  15. {
  16.     private OfferService $offerService;
  17.     public function __construct(OfferService $offerService)
  18.     {
  19.         $this->offerService $offerService;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             GenericPageLoadedEvent::class => 'onPageLoaded'
  25.         ];
  26.     }
  27.     public function onPageLoaded(GenericPageLoadedEvent $event): void
  28.     {
  29.         $event->getPage()->addExtension(
  30.             'premsIndividualOffer',
  31.             new ArrayStruct([
  32.                 'isOfferRequestAllowed' => $this->offerService->isOfferRequestAllowed($event->getSalesChannelContext()),
  33.                 'isOfferNavAllowed' => $this->offerService->isOfferNavAllowed($event->getSalesChannelContext()),
  34.             ])
  35.         );
  36.     }
  37. }