<?php
declare(strict_types=1);
namespace NetInventors\NetiNextEasyCoupon\Subscriber;
use NetInventors\NetiNextEasyCoupon\Service\ConditionService\ConditionErrorService;
use NetInventors\NetiNextEasyCoupon\Struct\ConditionErrorStruct;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PageSubscriber implements EventSubscriberInterface
{
private ConditionErrorService $conditionErrorService;
public function __construct(
ConditionErrorService $conditionErrorService
) {
$this->conditionErrorService = $conditionErrorService;
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onGenericPageLoaded',
];
}
public function onGenericPageLoaded(GenericPageLoadedEvent $event): void
{
$conditionErrorStruct = ConditionErrorStruct::fromError($this->conditionErrorService->get());
$event->getPage()->addExtension('netiEcConditionError', $conditionErrorStruct);
}
}