Trying to get checkout steps of an order outside of checkout pages throws an error.

Created on 15 December 2017, over 7 years ago
Updated 16 December 2024, 7 months ago

Trying to get checkout steps of an order outside of checkout pages throws an error. Starting with an order

    /** @var \Drupal\commerce_order\Entity\OrderInterface $order */

and calling

    $container = \Drupal::getContainer();
   
    /** @var Drupal\commerce_checkout\CheckoutOrderManagerInterface $order_manager */
    $order_manager = $container->get('commerce_checkout.checkout_order_manager');

    /** @var \Drupal\commerce_checkout\Entity\CheckoutFlowInterface $checkout_flow */
    $checkout_flow = $order_manager->getCheckoutFlow($order);

    /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface $checkout_flow_plugin */
    $checkout_flow_plugin = $checkout_flow->getPlugin();
    
    /** @var array $steps */
    $steps = $checkout_flow_plugin->getVisibleSteps();

the expected behavior is to get an array of the checkout steps of the $order we started with. However, this is not the case. The following happens:

  • If we are in a page with a commerce_order parameter the steps of that order are return
  • Else an error " Call to a member function on null" is thrown in the isVisible() method of the first checkout pane.
🐛 Bug report
Status

Needs review

Version

2.0

Component

Checkout

Created by

🇬🇷Greece s.messaris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024