custom/plugins/S360TaxSwitch/src/Storefront/Subscriber/CustomerLoginEventSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace S360\TaxSwitch\Storefront\Subscriber;
  4. use S360\TaxSwitch\Service\TaxStateHelper;
  5. use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CustomerLoginEventSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var TaxStateHelper
  11.      */
  12.     protected TaxStateHelper $taxStateHelper;
  13.     /**
  14.      * CustomerLoginEventSubscriber constructor.
  15.      */
  16.     public function __construct(TaxStateHelper $taxStateHelper)
  17.     {
  18.         $this->taxStateHelper $taxStateHelper;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             CustomerLoginEvent::class => 'persistTaxChoice'
  24.         ];
  25.     }
  26.     /**
  27.      * @param CustomerLoginEvent $event
  28.      */
  29.     public function persistTaxChoice(CustomerLoginEvent $event): void
  30.     {
  31.         $context $event->getContext();
  32.         $customer $event->getCustomer();
  33.         $isGross true;
  34.         $company null;
  35.         if($customer){
  36.             $company $customer->getCompany();
  37.         }
  38.         // if registered with company, company name returned, else null
  39.         if(isset($company)){
  40.             $isGross false;  
  41.         }
  42.         $this->taxStateHelper->persistTaxChoiceToCustomer($context$customer$isGross);
  43.         $this->taxStateHelper->persistTaxChoiceToCookie($isGross);
  44.     }
  45. }