<?php declare(strict_types=1);
namespace Samson\Subscriber;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2022
*
***/
use Samson\Event\C4CLeadCreationFinishedEvent;
use Samson\Event\CustomerAdminActivationEvent;
use Samson\Event\CustomerRegistrationFinishedEvent;
use Samson\Event\NE53NewsletterConfirmEvent;
use Samson\Event\NE53NewsletterRegisterEvent;
use Samson\Event\NE53NewsletterUnsubscribeEvent;
use Samson\Event\ReviewWrittenEvent;
use Samson\Event\Sap\SapCustomerAddressSynchronizationEvent;
use Samson\Event\Sap\SapCustomerRegistrationErrorEvent;
use Samson\Event\Sap\SapPriceUpdateEvent;
use Samson\Event\Sap\SapProductCreateEvent;
use Samson\Event\Sap\SapProductUpdateEvent;
use Samson\Event\TradeFairProductSelectionEvent;
use Samson\Event\UserInvitedEvent;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEventSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
public function __construct(BusinessEventCollector $businessEventCollector)
{
$this->businessEventCollector = $businessEventCollector;
}
public static function getSubscribedEvents(): array
{
return [
BusinessEventCollectorEvent::NAME => 'onBusinessEventCollectorEvent',
];
}
public function onBusinessEventCollectorEvent(BusinessEventCollectorEvent $event): void
{
$events = [
ReviewWrittenEvent::class => ReviewWrittenEvent::$eventName,
SapPriceUpdateEvent::class => SapPriceUpdateEvent::EVENT_NAME,
SapProductCreateEvent::class => SapProductCreateEvent::EVENT_NAME,
SapProductUpdateEvent::class => SapProductUpdateEvent::EVENT_NAME,
SapCustomerRegistrationErrorEvent::class => SapCustomerRegistrationErrorEvent::EVENT_NAME,
SapCustomerAddressSynchronizationEvent::class => SapCustomerAddressSynchronizationEvent::EVENT_NAME,
CustomerRegistrationFinishedEvent::class => CustomerRegistrationFinishedEvent::EVENT_NAME,
TradeFairProductSelectionEvent::class => TradeFairProductSelectionEvent::EVENT_NAME,
C4CLeadCreationFinishedEvent::class => C4CLeadCreationFinishedEvent::EVENT_NAME,
CustomerAdminActivationEvent::class => CustomerAdminActivationEvent::EVENT_NAME,
NE53NewsletterConfirmEvent::class => NE53NewsletterConfirmEvent::EVENT_NAME,
NE53NewsletterRegisterEvent::class => NE53NewsletterRegisterEvent::EVENT_NAME,
NE53NewsletterUnsubscribeEvent::class => NE53NewsletterUnsubscribeEvent::EVENT_NAME,
UserInvitedEvent::class => UserInvitedEvent::EVENT_NAME
];
foreach ($events as $class => $eventName) {
$definition = $this->businessEventCollector->define($class, $eventName);
$event->getCollection()->set($eventName, $definition);
}
}
}