<?php declare(strict_types=1);
namespace Uandi\UandiEfbErpSynchronization\Subscriber;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Shopware\Storefront\Page\PageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Uandi\UandiEfbErpSynchronization\Service\Document\Lists\ListingServiceFactory;
class AccountMenuSubscriber implements EventSubscriberInterface
{
private ListingServiceFactory $listingServiceFactory;
public static function getSubscribedEvents(): array
{
return [GenericPageLoadedEvent::class => 'addAvailableErpDocumentTypes'];
}
public function __construct(ListingServiceFactory $listingServiceFactory)
{
$this->listingServiceFactory = $listingServiceFactory;
}
public function addAvailableErpDocumentTypes(PageLoadedEvent $event): void
{
if (null === $event->getSalesChannelContext()->getCustomer()) {
return;
}
$event->getPage()->addExtension(
'availableErpDocumentTypes',
new ArrayStruct($this->listingServiceFactory->getAvailableTypes())
);
}
}