diff --git a/spec/EventListener/OrderCreationListenerSpec.php b/spec/EventListener/OrderCreationListenerSpec.php index c2ba19ca..8379385c 100644 --- a/spec/EventListener/OrderCreationListenerSpec.php +++ b/spec/EventListener/OrderCreationListenerSpec.php @@ -43,10 +43,10 @@ function it_completes_order_before_creation( $event->getSubject()->willReturn($order); $stateMachineFactory->get($order, 'sylius_order_checkout')->willReturn($stateMachine); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->shouldBeCalled(); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->shouldBeCalled(); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_COMPLETE)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_ADDRESS)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)->shouldBeCalled(); + $stateMachine->can(OrderCheckoutTransitions::TRANSITION_COMPLETE)->shouldBeCalled(); $this->completeOrderBeforeCreation($event); } diff --git a/src/EventListener/OrderCreationListener.php b/src/EventListener/OrderCreationListener.php index 6e90beab..6239e0ea 100644 --- a/src/EventListener/OrderCreationListener.php +++ b/src/EventListener/OrderCreationListener.php @@ -40,9 +40,17 @@ public function completeOrderBeforeCreation(GenericEvent $event): void Assert::isInstanceOf($order, OrderInterface::class); $stateMachine = $this->stateMachineFactory->get($order, 'sylius_order_checkout'); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_ADDRESS); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT); - $stateMachine->apply(OrderCheckoutTransitions::TRANSITION_COMPLETE); + $transitions = [ + OrderCheckoutTransitions::TRANSITION_ADDRESS, + OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING, + OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT, + OrderCheckoutTransitions::TRANSITION_COMPLETE, + ]; + + foreach ($transitions as $transition) { + if ($stateMachine->can($transition)) { + $stateMachine->apply($transition); + } + } } }