custom/plugins/TemplaidInvoices/src/Subscriber/CustomerSubscriber.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TemplaidInvoices\Subscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use TemplaidInvoices\Service\SyncService;
  7. class CustomerSubscriber implements EventSubscriberInterface
  8. {
  9.     private LoggerInterface $logger;
  10.     private SyncService $syncService;
  11.     public function __construct(
  12.         LoggerInterface $logger,
  13.         SyncService     $syncService
  14.     )
  15.     {
  16.         $this->logger $logger;
  17.         $this->syncService $syncService;
  18.     }
  19.     /**
  20.      * @return array|string[]
  21.      */
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [
  25.             CustomerLoginEvent::class => 'onCustomerLogin'
  26.         ];
  27.     }
  28.     /**
  29.      * @param CustomerLoginEvent $event
  30.      */
  31.     public function onCustomerLogin(CustomerLoginEvent $event): void
  32.     {
  33.         try {
  34.             $this->syncService->syncInvoices($event->getCustomerId(), $event->getCustomer()->getCustomerNumber(), $event->getSalesChannelContext());
  35.             $this->syncService->syncWishlistItems($event->getCustomerId(), $event->getCustomer(), $event->getSalesChannelContext());
  36.         } catch (\Exception $e) {
  37.             $this->logger->error($e->getMessage());
  38.         }
  39.     }
  40. }