custom/plugins/MolliePayments/src/Subscriber/OrderDeliverySubscriber.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Kiener\MolliePayments\Subscriber;
  3. use Kiener\MolliePayments\Facade\MollieShipment;
  4. use Shopware\Core\System\StateMachine\Aggregation\StateMachineTransition\StateMachineTransitionActions;
  5. use Shopware\Core\System\StateMachine\Event\StateMachineStateChangeEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Throwable;
  8. class OrderDeliverySubscriber implements EventSubscriberInterface
  9. {
  10.     /** @var MollieShipment */
  11.     private $mollieShipment;
  12.     public function __construct(
  13.         MollieShipment $mollieShipment
  14.     )
  15.     {
  16.         $this->mollieShipment $mollieShipment;
  17.     }
  18.     /**
  19.      * @return array
  20.      */
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             'state_machine.order_delivery.state_changed' => 'onOrderDeliveryChanged',
  25.         ];
  26.     }
  27.     public function onOrderDeliveryChanged(StateMachineStateChangeEvent $event): void
  28.     {
  29.         if ($event->getTransitionSide() !== StateMachineStateChangeEvent::STATE_MACHINE_TRANSITION_SIDE_ENTER) {
  30.             return;
  31.         }
  32.         $transitionName $event->getTransition()->getTransitionName();
  33.         if ($transitionName !== StateMachineTransitionActions::ACTION_SHIP) {
  34.             return;
  35.         }
  36.         $this->mollieShipment->setShipment($event->getTransition()->getEntityId(), $event->getContext());
  37.     }
  38. }