<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\PrestashopConnectorBundle\EventSubscriber;
use ReflectionClass;
use App\Services\CheckBundleInstall;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Bluue\PrestashopConnectorBundle\Message\UpdateOrderOptionsCarrierToPrestaMessage;
class OrderOptionsEditCarrierSubscriber implements EventSubscriberInterface
{
/**
* @var MessageBusInterface $messageBus
*/
protected MessageBusInterface $messageBus;
public function __construct(MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('shipments-bundle')) {
$reflectionClass = new ReflectionClass('Bluue\ShipmentsBundle\Event\OrderOptionsEditCarrierEvent');
return [
$reflectionClass->getConstant('POST_SUBMIT') => 'postSubmit'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function postSubmit(object $event): void
{
$this->messageBus->dispatch(
new UpdateOrderOptionsCarrierToPrestaMessage($event->getOrderOptions()->getId()->toRfc4122())
);
}
}