<?php declare(strict_types=1);/** * (c) 2Hats Logic Solutions <info@2hatslogic.com> */namespace Hatslogic\ImplifyExtended\Subscriber;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Doctrine\DBAL\Connection;use Symfony\Component\DependencyInjection\ContainerInterface;use Symfony\Component\HttpKernel\KernelEvents;use Symfony\Component\HttpKernel\Event\RequestEvent;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\Routing\RouterInterface;use Symfony\Component\HttpKernel\Event\ResponseEvent;use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;use Shopware\Core\Checkout\Customer\Event\CustomerLogoutEvent;use Symfony\Component\HttpFoundation\Session\Session;class AccountSubscriber implements EventSubscriberInterface{ /** * @var ContainerInterface */ protected $container; /** * @var Connection */ private $connection; /** * @var RouterInterface */ private $router; /** * @var RequestStack */ private $requestStack; /** @var ResponseEvent */ private $event; /** * @var Session */ private $session; public function __construct( ContainerInterface $container, Connection $connection, RouterInterface $router, RequestStack $requestStack, Session $session ) { $this->container = $container; $this->connection = $connection; $this->router = $router; $this->requestStack = $requestStack; $this->session = $session; } public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => 'kernelEventsRequest', CustomerLoginEvent::class => 'afterSuccessfulLogin', CustomerLogoutEvent::class => 'afterLogout' ]; } public function afterSuccessfulLogin(CustomerLoginEvent $event) { $this->session->set('customerLoggedIn', true); return; } public function afterLogout(CustomerLogoutEvent $event) { if($this->session->has('customerLoggedIn')) { $this->session->remove('customerLoggedIn'); } return; } public function kernelEventsRequest(RequestEvent $event) { $request = $event->getRequest(); $attributes = $request->attributes; $route = $attributes->get('_route'); if($this->session->has('customerLoggedIn') && $route == 'frontend.account.login.page') { echo "<script type='text/javascript'> document.location = '".$this->router->generate('frontend.account.home.page')."'; </script>"; exit; } return; }}