vendor/store.shopware.com/crswcleverreachofficial/src/Subscriber/Products/ProductSubscriber.php line 58

Open in your IDE?
  1. <?php
  2. namespace Crsw\CleverReachOfficial\Subscriber\Products;
  3. use Crsw\CleverReachOfficial\Components\Utility\Bootstrap;
  4. use Crsw\CleverReachOfficial\Components\Utility\Initializer;
  5. use Shopware\Core\Content\Product\ProductEvents;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. /**
  11.  * Class ProductSubscriber
  12.  *
  13.  * @package Crsw\CleverReachOfficial\Subscriber\Products
  14.  */
  15. class ProductSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var RequestStack
  19.      */
  20.     private $requestStack;
  21.     /**
  22.      * @var SessionInterface
  23.      */
  24.     private $session;
  25.     /**
  26.      * ProductSubscriber constructor.
  27.      *
  28.      * @param RequestStack $requestStack
  29.      * @param SessionInterface $session
  30.      * @param Initializer $initializer
  31.      */
  32.     public function __construct(SessionInterface $sessionRequestStack $requestStackInitializer $initializer)
  33.     {
  34.         Bootstrap::init();
  35.         $initializer->registerServices();
  36.         $this->requestStack $requestStack;
  37.         $this->session $session;
  38.     }
  39.     /**
  40.      * @return array
  41.      */
  42.     public static function getSubscribedEvents(): array
  43.     {
  44.         return [
  45.             ProductEvents::PRODUCT_LOADED_EVENT => 'onProductLoaded'
  46.         ];
  47.     }
  48.     /**
  49.      * @param EntityLoadedEvent $event
  50.      */
  51.     public function onProductLoaded(EntityLoadedEvent $event): void
  52.     {
  53.         $request $this->requestStack->getCurrentRequest();
  54.         if ($request) {
  55.             $crMailing $request->get('crmailing');
  56.             if (!empty($crMailing)) {
  57.                 $this->session->set('crMailing'$crMailing);
  58.             }
  59.         }
  60.     }
  61. }