custom/plugins/NetiNextEasyCoupon/src/Subscriber/BusinessEvent.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Subscriber;
  4. use NetInventors\NetiNextEasyCoupon\Constants\BusinessEventsConstants;
  5. use NetInventors\NetiNextEasyCoupon\Constants\FlowConstants;
  6. use NetInventors\NetiNextEasyCoupon\Service\CheckService;
  7. use Shopware\Core\Framework\Event\BusinessEventCollector;
  8. use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
  9. use Shopware\Core\Framework\Event\BusinessEventDefinition;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class BusinessEvent implements EventSubscriberInterface
  12. {
  13.     protected BusinessEventCollector $collector;
  14.     private CheckService             $checkService;
  15.     public function __construct(BusinessEventCollector $collector, CheckService $checkService)
  16.     {
  17.         $this->collector    = $collector;
  18.         $this->checkService = $checkService;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             BusinessEventCollectorEvent::NAME => 'onRegisterEvent',
  24.         ];
  25.     }
  26.     public function onRegisterEvent(BusinessEventCollectorEvent $event): void
  27.     {
  28.         $definitionClasses = BusinessEventsConstants::EVENT_CLASSES;
  29.         if ($this->checkService->isFlowsAvailable()) {
  30.             $definitionClasses = FlowConstants::EVENT_CLASSES;
  31.         }
  32.         foreach ($definitionClasses as $class) {
  33.             $eventDefinition = $this->collector->define($class);
  34.             if ($eventDefinition instanceof BusinessEventDefinition) {
  35.                 $event->getCollection()->set($class, $eventDefinition);
  36.             }
  37.         }
  38.     }
  39. }