custom/static-plugins/GlobusSW6/src/Subscriber/Session/SessionSubscriber.php line 54

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace GlobusSW6\Subscriber\Session;
  3. use GlobusSW6\Service\App\AppService;
  4. use GlobusSW6\Service\StoreLocator\StoreSwitchService;
  5. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. class SessionSubscriber implements EventSubscriberInterface
  9. {
  10.     /** @var StoreSwitchService */
  11.     private $storeSwitchService;
  12.     /** @var AppService */
  13.     private $appService;
  14.     /**
  15.      * @param StoreSwitchService $storeSwitchService
  16.      * @param AppService $appService
  17.      */
  18.     public function __construct(StoreSwitchService $storeSwitchServiceAppService $appService)
  19.     {
  20.         $this->storeSwitchService $storeSwitchService;
  21.         $this->appService $appService;
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             GenericPageLoadedEvent::class => 'appendSessionVariables'
  27.         ];
  28.     }
  29.     public function appendSessionVariables(GenericPageLoadedEvent $event)
  30.     {
  31.         /** @var Session $session */
  32.         $session $event->getRequest()->getSession();
  33.         $salesChannelContext $event->getSalesChannelContext();
  34.         $selectedStore $session->get('ianeoCurrentStore');
  35.         if (is_null($selectedStore)) { // there always has to be a selected store: set fallback store
  36.             $session->set("setFallbackStoreInProgress","start");
  37.             $this->storeSwitchService->setFallbackStore($session$salesChannelContext);
  38.             $session->set("setFallbackStoreInProgress","end");
  39.         }
  40.         $event->getPage()->assign([
  41.             'ianeoHitsellerIsApp' => $this->appService->isAppFromSession($session),
  42.             'ianeoCurrentStore' => $session->get('ianeoCurrentStore'),
  43.             'ianeoIsFallbackStore' => $session->get('isFallbackStore'),
  44.             'ianeoCartViolations' => $session->get('ianeoCartViolations'),
  45.             'offcanvasModal' => $session->get('offcanvasModal')
  46.         ]);
  47.     }
  48. }