class CheckoutOrderManager in Commerce Core 8.2
Manages checkout flows for orders.
Hierarchy
- class \Drupal\commerce_checkout\CheckoutOrderManager implements CheckoutOrderManagerInterface
Expanded class hierarchy of CheckoutOrderManager
1 string reference to 'CheckoutOrderManager'
- commerce_checkout.services.yml in modules/
checkout/ commerce_checkout.services.yml - modules/checkout/commerce_checkout.services.yml
1 service uses CheckoutOrderManager
File
- modules/
checkout/ src/ CheckoutOrderManager.php, line 11
Namespace
Drupal\commerce_checkoutView source
class CheckoutOrderManager implements CheckoutOrderManagerInterface {
/**
* The chain checkout flow resolver.
*
* @var \Drupal\commerce_checkout\Resolver\ChainCheckoutFlowResolverInterface
*/
protected $chainCheckoutFlowResolver;
/**
* Constructs a new CheckoutOrderManager object.
*
* @param \Drupal\commerce_checkout\Resolver\ChainCheckoutFlowResolverInterface $chain_checkout_flow_resolver
* The chain checkout flow resolver.
*/
public function __construct(ChainCheckoutFlowResolverInterface $chain_checkout_flow_resolver) {
$this->chainCheckoutFlowResolver = $chain_checkout_flow_resolver;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CheckoutOrderManager:: |
protected | property | The chain checkout flow resolver. | |
CheckoutOrderManager:: |
public | function |
Gets the order's checkout flow. Overrides CheckoutOrderManagerInterface:: |
|
CheckoutOrderManager:: |
public | function |
Gets the order's checkout step ID. Overrides CheckoutOrderManagerInterface:: |
|
CheckoutOrderManager:: |
public | function | Constructs a new CheckoutOrderManager object. |