public function CheckoutOrderManager::getCheckoutStepId in Commerce Core 8.2
Gets the order's checkout step ID.
Ensures that the user is allowed to access the requested step ID, when given. In case the requested step ID is empty, invalid, or not allowed, a different step ID will be returned.
Parameters
\Drupal\commerce_order\Entity\OrderInterface $order: The order.
string $requested_step_id: (Optional) The requested step ID.
Return value
string The checkout step ID.
Overrides CheckoutOrderManagerInterface::getCheckoutStepId
File
- modules/
checkout/ src/ CheckoutOrderManager.php, line 46
Class
- CheckoutOrderManager
- Manages checkout flows for orders.
Namespace
Drupal\commerce_checkoutCode
public function getCheckoutStepId(OrderInterface $order, $requested_step_id = NULL) {
// Customers can't edit orders that have already been placed.
if ($order
->getState()
->getId() != 'draft') {
return 'complete';
}
$checkout_flow = $this
->getCheckoutFlow($order);
$available_step_ids = array_keys($checkout_flow
->getPlugin()
->getVisibleSteps());
$selected_step_id = $order
->get('checkout_step')->value;
$selected_step_id = $selected_step_id ?: reset($available_step_ids);
if (empty($requested_step_id) || $requested_step_id == $selected_step_id) {
return $selected_step_id;
}
if (in_array($requested_step_id, $available_step_ids)) {
// Allow access to a previously completed step.
$requested_step_index = array_search($requested_step_id, $available_step_ids);
$selected_step_index = array_search($selected_step_id, $available_step_ids);
if ($requested_step_index <= $selected_step_index) {
$selected_step_id = $requested_step_id;
}
}
return $selected_step_id;
}