custom/plugins/CioBudget/src/Subscriber/RegisterBudgetInSessionSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace CioBudget\Subscriber;
  3. use CioBudget\Service\SessionService;
  4. use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
  5. use Shopware\Core\Checkout\Customer\Event\CustomerLogoutEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class RegisterBudgetInSessionSubscriber implements EventSubscriberInterface
  8. {
  9.     private SessionService $sessionService;
  10.     public function __construct(SessionService $sessionService)
  11.     {
  12.         $this->sessionService $sessionService;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             CustomerLoginEvent::class => 'onLogin',
  18.             CustomerLogoutEvent::class => 'onLogout'
  19.         ];
  20.     }
  21.     public function onLogin(CustomerLoginEvent $event)
  22.     {
  23.         $customer $event->getCustomer();
  24.         $this->sessionService->setCustomerBudgetInSession($customer$event->getSalesChannelContext());
  25.     }
  26.     public function onLogout(CustomerLogoutEvent $event)
  27.     {
  28.         $this->sessionService->removeOldActiveBudget();
  29.     }
  30. }