Skip to content

Commit 87dc7bb

Browse files
Allow skipping shipping/payment steps in express checkout
1 parent 3153b3c commit 87dc7bb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Controller/ProcessPayPalOrderAction.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public function __invoke(Request $request): Response
108108

109109
$address = $this->addressFactory->createNew();
110110

111+
$stateMachine = $this->getStateMachine();
112+
111113
if ($order->isShippingRequired()) {
112114
$name = explode(' ', $purchaseUnit['shipping']['name']['full_name']);
113115
$address->setLastName(array_pop($name) ?? '');
@@ -117,8 +119,13 @@ public function __invoke(Request $request): Response
117119
$address->setPostcode($purchaseUnit['shipping']['address']['postal_code']);
118120
$address->setCountryCode($purchaseUnit['shipping']['address']['country_code']);
119121

120-
$this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
121-
$this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING);
122+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
123+
124+
if ($stateMachine->can($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING)) {
125+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING);
126+
} elseif ($stateMachine->can($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SKIP_SHIPPING)) {
127+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SKIP_SHIPPING);
128+
}
122129
} else {
123130
$address->setFirstName($customer->getFirstName());
124131
$address->setLastName($customer->getLastName());
@@ -130,13 +137,17 @@ public function __invoke(Request $request): Response
130137
$address->setPostcode($defaultAddress ? $defaultAddress->getPostcode() : '');
131138
$address->setCountryCode($data['payer']['address']['country_code']);
132139

133-
$this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
140+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
134141
}
135142

136143
$order->setShippingAddress(clone $address);
137144
$order->setBillingAddress(clone $address);
138145

139-
$this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
146+
if ($stateMachine->can($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT)) {
147+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
148+
} elseif ($stateMachine->can($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SKIP_PAYMENT)) {
149+
$stateMachine->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SKIP_PAYMENT);
150+
}
140151

141152
$this->orderManager->flush();
142153

0 commit comments

Comments
 (0)