<?php declare(strict_types=1);
namespace Dvdw\AutoEmail\Content\Product\Subscriber;
use Dvdw\AutoEmail\Content\Product\Event\ProductInsertedEvent;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEventCollectorSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
public function __construct(BusinessEventCollector $businessEventCollector) {
$this->businessEventCollector = $businessEventCollector;
}
public static function getSubscribedEvents(): iterable
{
return [
BusinessEventCollectorEvent::NAME => ['onAddProductInsertedEvent', 1000],
];
}
public function onAddProductInsertedEvent(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$definition = $this->businessEventCollector->define(ProductInsertedEvent::class);
if (!$definition) {
return;
}
$collection->set($definition->getName(), $definition);
}
}