<?php declare(strict_types=1);
namespace TemplaidInvoices\Subscriber;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use TemplaidInvoices\Service\SyncService;
class CustomerSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
private SyncService $syncService;
public function __construct(
LoggerInterface $logger,
SyncService $syncService
)
{
$this->logger = $logger;
$this->syncService = $syncService;
}
/**
* @return array|string[]
*/
public static function getSubscribedEvents()
{
return [
CustomerLoginEvent::class => 'onCustomerLogin'
];
}
/**
* @param CustomerLoginEvent $event
*/
public function onCustomerLogin(CustomerLoginEvent $event): void
{
try {
$this->syncService->syncInvoices($event->getCustomerId(), $event->getCustomer()->getCustomerNumber(), $event->getSalesChannelContext());
$this->syncService->syncWishlistItems($event->getCustomerId(), $event->getCustomer(), $event->getSalesChannelContext());
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
}
}
}