<?php declare(strict_types=1);
namespace Nd\Srs\Subscriber;
use Nd\Srs\Core\Framework\Event\CancelEvent;
use Nd\Srs\Core\Framework\Event\OnlineAccountCreatedEvent;
use Nd\Srs\Core\Framework\Event\ReturnEvent;
use Nd\Srs\Core\Framework\Event\TrackingCodeAddedEvent;
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()
{
return [
BusinessEventCollectorEvent::NAME => ['addSrsEvents', 1000],
];
}
public function addSrsEvents(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$definitions = [
$this->businessEventCollector->define(TrackingCodeAddedEvent::class),
$this->businessEventCollector->define(OnlineAccountCreatedEvent::class),
$this->businessEventCollector->define(CancelEvent::class),
$this->businessEventCollector->define(ReturnEvent::class)];
foreach($definitions as $definition){
if (!$definition) {
continue;
}
$collection->set($definition->getName(), $definition);
}
}
}