src/Core/Subscriber/Order/OrderStateSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bodymed\Webshop\Core\Subscriber\Order;
  4. use Bodymed\Webshop\Messenger\Messages\Order\OrderTransactionStateChanged;
  5. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Messenger\MessageBusInterface;
  8. class OrderStateSubscriber implements EventSubscriberInterface
  9. {
  10.     private MessageBusInterface $messageBus;
  11.     public function __construct(MessageBusInterface $messageBus)
  12.     {
  13.         $this->messageBus $messageBus;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             'state_enter.order_transaction.state.paid' => 'onEnterOrderTransactionStatePaid',
  19.         ];
  20.     }
  21.     public function onEnterOrderTransactionStatePaid(OrderStateMachineStateChangeEvent $event): void
  22.     {
  23.         $this->dispatchMessage($event);
  24.     }
  25.     private function dispatchMessage(OrderStateMachineStateChangeEvent $event): void
  26.     {
  27.         $context $event->getContext();
  28.         $order $event->getOrder();
  29.         $salesChannelId $order->getSalesChannelId();
  30.         $this->messageBus->dispatch(OrderTransactionStateChanged::create($order$context$salesChannelId));
  31.     }
  32. }