custom/plugins/b2bsellerscore/src/Components/Order/Subscriber/OrderStateChangedSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace B2bSellersCore\Components\Order\Subscriber;
  3. use B2bSellersCore\Components\Order\Service\OrderMailRecipientServiceInterface;
  4. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Shopware\Core\Checkout\Order\Event\OrderStateChangeCriteriaEvent;
  7. class OrderStateChangedSubscriber implements EventSubscriberInterface
  8. {
  9.     private OrderMailRecipientServiceInterface $orderMailRecipientService;
  10.     public function __construct(
  11.         OrderMailRecipientServiceInterface $orderMailRecipientService
  12.     )
  13.     {
  14.         $this->orderMailRecipientService $orderMailRecipientService;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             OrderStateChangeCriteriaEvent::class => 'addB2bExtensionAssociations',
  20.             OrderStateMachineStateChangeEvent::class => [['replaceMailRecipients', -10]]
  21.         ];
  22.     }
  23.     public function replaceMailRecipients(OrderStateMachineStateChangeEvent $event): void
  24.     {
  25.         $recipients $this->orderMailRecipientService->getRecipientsByOrder($event->getOrder(), $event->getContext());
  26.         $event->getMailStruct()->setRecipients($recipients->getRecipients());
  27.     }
  28.     public function addB2bExtensionAssociations(OrderStateChangeCriteriaEvent $event)
  29.     {
  30.         $event->getCriteria()->addAssociations([
  31.             'b2bOrderExtension.employee',
  32.             'b2bOrderExtension.salesRepresentative'
  33.         ]);
  34.     }
  35. }