custom/plugins/MadMykey/src/Subscriber/LogoutSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Madco\Mykey\Subscriber;
  4. use Madco\Mykey\Constants;
  5. use Shopware\Core\Checkout\Customer\Event\CustomerLogoutEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. class LogoutSubscriber implements EventSubscriberInterface
  9. {
  10.     private RequestStack $requestStack;
  11.     public function __construct(RequestStack $requestStack)
  12.     {
  13.         $this->requestStack $requestStack;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             CustomerLogoutEvent::class => 'onCustomerLogout',
  19.         ];
  20.     }
  21.     public function onCustomerLogout(CustomerLogoutEvent $event): void
  22.     {
  23.         $request $this->requestStack->getCurrentRequest();
  24.         if ($request) {
  25.             $session $request->getSession();
  26.             $session->remove(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE);
  27.             $session->remove(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE);
  28.         }
  29.         $event->getContext()->removeExtension(Constants::MYKEY_AFFILIATE_CONTEXT_EXTENSION_KEY);
  30.         $event->getContext()->removeExtension(Constants::MYKEY_PARTNER_CONTEXT_EXTENSION_KEY);
  31.         $event->getSalesChannelContext()->removeExtension(Constants::MYKEY_AFFILIATE_CONTEXT_EXTENSION_KEY);
  32.         $event->getSalesChannelContext()->removeExtension(Constants::MYKEY_PARTNER_CONTEXT_EXTENSION_KEY);
  33.     }
  34. }