<?php declare(strict_types=1);
namespace Dvdw\AutoEmail\Checkout\Customer\Subscriber;
use Dvdw\AutoEmail\Checkout\Customer\Event\NoParticipationEvent;
use Dvdw\AutoEmail\Checkout\Customer\Event\NoPromotionEvent;
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 => [['onAddNoParticipationEvent', 1001], ['onAddNoPromotionEvent', 1002]],
];
}
public function onAddNoParticipationEvent(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$definition = $this->businessEventCollector->define(NoParticipationEvent::class);
if (!$definition) {
return;
}
$collection->set($definition->getName(), $definition);
}
public function onAddNoPromotionEvent(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$definition = $this->businessEventCollector->define(NoPromotionEvent::class);
if (!$definition) {
return;
}
$collection->set($definition->getName(), $definition);
}
}