<?php declare(strict_types=1);
namespace Jlau\LoginAsCustomer\Subscriber;
use Jlau\LoginAsCustomer\Controller\LoginAsCustomer;
use Shopware\Core\Checkout\Customer\Event\CustomerBeforeLoginEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class BeforeLoginSubscriber implements EventSubscriberInterface
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public static function getSubscribedEvents()
{
return [CustomerBeforeLoginEvent::class => 'removeUserIdFromSessionBeforeLogin'];
}
public function removeUserIdFromSessionBeforeLogin(CustomerBeforeLoginEvent $event)
{
$this->requestStack->getSession()->remove(LoginAsCustomer::SESSION_NAME);
}
}