custom/plugins/CioBudget/src/Subscriber/RegisterBudgetInSession.php line 31

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 Shopware\Core\System\SalesChannel\Context\SalesChannelContextPersister;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class RegisterBudgetInSession implements EventSubscriberInterface
  9. {
  10.     private SessionService $sessionService;
  11.     private SalesChannelContextPersister $salesChannelContextPersister;
  12.     public function setSessionService(SessionService $sessionServiceSalesChannelContextPersister $salesChannelContextPersister)
  13.     {
  14.         $this->sessionService $sessionService;
  15.         $this->salesChannelContextPersister $salesChannelContextPersister;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CustomerLoginEvent::class => 'onLogin',
  21.             CustomerLogoutEvent::class => 'onLogout'
  22.         ];
  23.     }
  24.     public function onLogin(CustomerLoginEvent $event)
  25.     {
  26.         $customer $event->getCustomer();
  27.         $this->sessionService->setCustomerBudgetInSession($customer$event->getSalesChannelContext());
  28.     }
  29.     public function onLogout(CustomerLogoutEvent $event)
  30.     {
  31.         $this->sessionService->removeOldActiveBudget();
  32.     }
  33. }