<?php
namespace WabsPIM\Subscriber;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use WabsPIM\Core\Content\PIM\Event\ProductDraftCreatedEvent;
use WabsPIM\Core\Content\PIM\Event\ProductDraftStateChangedEvent;
class BusinessEventCollectorSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
public function __construct(BusinessEventCollector $businessEventCollector)
{
$this->businessEventCollector = $businessEventCollector;
}
public static function getSubscribedEvents()
{
return [
BusinessEventCollectorEvent::NAME => ['onCollectBusinessEvents', 1000],
];
}
public function onCollectBusinessEvents(BusinessEventCollectorEvent $event): void
{
$collection = $event->getCollection();
$definition = $this->businessEventCollector->define(ProductDraftCreatedEvent::class);
if ($definition) {
$collection->set($definition->getName(), $definition);
}
$definition = $this->businessEventCollector->define(ProductDraftStateChangedEvent::class);
if ($definition) {
$collection->set($definition->getName(), $definition);
}
}
}