CheckoutOrderManager.php in Commerce Core 8.2
File
modules/checkout/src/CheckoutOrderManager.php
View source
<?php
namespace Drupal\commerce_checkout;
use Drupal\commerce_checkout\Resolver\ChainCheckoutFlowResolverInterface;
use Drupal\commerce_order\Entity\OrderInterface;
class CheckoutOrderManager implements CheckoutOrderManagerInterface {
protected $chainCheckoutFlowResolver;
public function __construct(ChainCheckoutFlowResolverInterface $chain_checkout_flow_resolver) {
$this->chainCheckoutFlowResolver = $chain_checkout_flow_resolver;
}
public function getCheckoutFlow(OrderInterface $order) {
if (!$order
->get('checkout_flow')->entity) {
$checkout_flow = $this->chainCheckoutFlowResolver
->resolve($order);
$order
->set('checkout_flow', $checkout_flow);
$order
->save();
}
return $order
->get('checkout_flow')->entity;
}
public function getCheckoutStepId(OrderInterface $order, $requested_step_id = NULL) {
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)) {
$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;
}
}