<?php
declare(strict_types=1);
namespace NetInventors\NetiNextEasyCouponDesigns\Subscriber;
use NetInventors\NetiNextEasyCouponDesigns\Constants\BusinessEventsConstants;
use NetInventors\NetiNextEasyCouponDesigns\Constants\FlowConstants;
use NetInventors\NetiNextEasyCouponDesigns\Service\CheckService;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Shopware\Core\Framework\Event\BusinessEventDefinition;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEvent implements EventSubscriberInterface
{
protected BusinessEventCollector $collector;
private CheckService $checkService;
public function __construct(BusinessEventCollector $collector, CheckService $checkService)
{
$this->collector = $collector;
$this->checkService = $checkService;
}
public static function getSubscribedEvents(): array
{
return [
BusinessEventCollectorEvent::NAME => 'onRegisterEvent',
];
}
public function onRegisterEvent(BusinessEventCollectorEvent $event): void
{
$definitionClasses = BusinessEventsConstants::EVENT_CLASSES;
if ($this->checkService->isFlowsAvailable()) {
$definitionClasses = FlowConstants::EVENT_CLASSES;
}
foreach ($definitionClasses as $class) {
$eventDefinition = $this->collector->define($class);
if ($eventDefinition instanceof BusinessEventDefinition) {
$event->getCollection()->set($class, $eventDefinition);
}
}
}
}