custom/plugins/ZeobvGetNotified/src/FlowBuilder/Subscriber/BusinessEventCollectorSubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Zeobv\GetNotified\FlowBuilder\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Framework\Event\BusinessEventCollector;
  5. use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
  6. use Shopware\Core\Framework\Event\BusinessEventCollectorResponse;
  7. use Zeobv\GetNotified\FlowBuilder\Aware\ProductAware;
  8. use Zeobv\GetNotified\FlowBuilder\Event\ProductBackInStockEvent;
  9. class BusinessEventCollectorSubscriber implements EventSubscriberInterface
  10. {
  11.     private BusinessEventCollector $businessEventCollector;
  12.     public function __construct(
  13.         BusinessEventCollector $businessEventCollector
  14.     ) {
  15.         $this->businessEventCollector $businessEventCollector;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             BusinessEventCollectorEvent::NAME => ['onAddEvent'1000],
  21.         ];
  22.     }
  23.     public function onAddEvent(BusinessEventCollectorEvent $event): void
  24.     {
  25.         $collection $event->getCollection();
  26.         $this->setEventsInCollection($collection);
  27.         $this->setAwareDefinitions($collection);
  28.     }
  29.     protected function setEventsInCollection(BusinessEventCollectorResponse $collection): void
  30.     {
  31.         $definition $this->businessEventCollector->define(ProductBackInStockEvent::class);
  32.         if (!$definition) {
  33.             return;
  34.         }
  35.         $collection->set($definition->getName(), $definition);
  36.     }
  37.     protected function setAwareDefinitions(BusinessEventCollectorResponse $collection): void
  38.     {
  39.         foreach ($collection->getElements() as $definition) {
  40.             if ($definition->getName() !== ProductBackInStockEvent::EVENT_NAME) {
  41.                 continue;
  42.             }
  43.             $definition->addAware(ProductAware::class);
  44.         }
  45.     }
  46. }