0

I'm trying to get the order information inside the mymodule_preprocess_page hook.

On the normal page I can get it via the $cart. But the $cart is not available on the checkout page anymore. How do I get the order information specifically the order_id and order_number.

This is what I do on other pages:

  $order_type = 'physical';
  $cart_provider = \Drupal::service('commerce_cart.cart_provider');
  $store = \Drupal::service('commerce_store.current_store')->getStore();
  $cart = $cart_provider->getCart($order_type, $store);
  if ($cart) {
    foreach ($cart->getItems() as $order_item) {
      $orderId = $order_item->get('purchased_entity')[0]->get('target_id')->getValue();
  }

1 Answer 1

2

The following should work:


  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = \Drupal::routeMatch()->getParameter('commerce_order');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.