vendor/store.shopware.com/agiqonoci/src/Subscriber/AccountSubscriber.php line 72

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace AgiqonOci\Subscriber;
  3. use AgiqonOci\Models\CxmlSession;
  4. use AgiqonOci\Models\OciSession;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Shopware\Storefront\Framework\Routing\Router;
  7. use Shopware\Storefront\Page\Account\CustomerGroupRegistration\CustomerGroupRegistrationPageLoadedEvent;
  8. use Shopware\Storefront\Page\Account\Document\DocumentPageLoadedEvent;
  9. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  10. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  11. use Shopware\Storefront\Page\Account\Order\AccountOrderDetailPageLoadedEvent;
  12. use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  13. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  14. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
  15. use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
  16. use Shopware\Storefront\Page\PageLoadedEvent;
  17. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\HttpFoundation\RedirectResponse;
  20. use Symfony\Component\Routing\RouterInterface;
  21. class AccountSubscriber implements EventSubscriberInterface
  22. {
  23.     private SystemConfigService $configService;
  24.     private string $redirectPath;
  25.     public function __construct(SystemConfigService $configServiceRouterInterface $router)
  26.     {
  27.         $this->configService $configService;
  28.         $this->redirectPath $router->generate('frontend.checkout.cart.page');
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             CustomerGroupRegistrationPageLoadedEvent::class => 'redirectToCart',
  34.             DocumentPageLoadedEvent::class => 'redirectToCart',
  35.             AccountLoginPageLoadedEvent::class => 'redirectToCart',
  36.             AccountEditOrderPageLoadedEvent::class => 'redirectToCart',
  37.             AccountOrderDetailPageLoadedEvent::class => 'redirectToCart',
  38.             AccountOrderPageLoadedEvent::class => 'redirectToCart',
  39.             AccountOverviewPageLoadedEvent::class => 'redirectToCart',
  40.             AccountPaymentMethodPageLoadedEvent::class => 'redirectToCart',
  41.             AccountProfilePageLoadedEvent::class => 'redirectToCart',
  42.             HeaderPageletLoadedEvent::class => 'onHeaderLoaded'
  43.         ];
  44.     }
  45.     /**
  46.      * Redirects to the checkout/cart from checkout/confirm and checkout/finish
  47.      *
  48.      * @param PageLoadedEvent $event
  49.      */
  50.     public function redirectToCart(PageLoadedEvent $event)
  51.     {
  52.         if ($event->getRequest()->getSession()->get(OciSession::OCI_SESSION_NAME)) {
  53.             $response = new RedirectResponse($this->redirectPath);
  54.             $response->send();
  55.         }
  56.     }
  57.     /**
  58.      * Gives information to the template, if OCI session exists, to remove the account icon.
  59.      *
  60.      * @param HeaderPageletLoadedEvent $event
  61.      */
  62.     public function onHeaderLoaded(HeaderPageletLoadedEvent $event)
  63.     {
  64.         $ociSession $event->getRequest()->getSession()->get(OciSession::OCI_SESSION_NAME);
  65.         if ($ociSession) {
  66.             $event->getPagelet()->assign(['AgiqonOciSession' => true]);
  67.             $showLogoutButton $this->configService->getBool('AgiqonOci.config.showLogoutButton'$event->getSalesChannelContext()->getSalesChannelId());
  68.             $event->getPagelet()->assign(['AgiqonOciShowLogoutButton' => $showLogoutButton]);
  69.             if($ociSession instanceof CxmlSession && $ociSession->getOperation() === CxmlSession::INSPECT) {
  70.                 $event->getPagelet()->assign([
  71.                    'AgiqonCxmlInspect' => true
  72.                 ]);
  73.             }
  74.         }
  75.     }
  76. }