Order number in template commerce-order--admin.html

Created on 9 June 2021, about 4 years ago
Updated 26 June 2025, 10 days ago

The order.order_number is not available in the template

The documentation at the head of commerce-order--admin.html template states that:

Available variables:
 * - attributes: HTML attributes for the wrapper.
 * - order: The rendered order fields.
 *   Use 'order' to print them all, or print a subset such as
 *   'order.order_number'. Use the following code to exclude the
 *   printing of a given field:
 *   @code
 *   {{ order|without('order_number') }}
 *   @endcode
 * - order_entity: The order entity.

However, order.order_number does not generate the order number through a customised template (generates a NULL).

After a bit of playing about found the following to work:

{{ order_entity.getOrderNumber }}

If this is a valid approach, can I suggest that the documentation within the template be altered.

🐛 Bug report
Status

Active

Version

2.40

Component

Order

Created by

🇬🇧United Kingdom robcarr Perthshire, Scotland

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.

  • 🇺🇸United States seanr

    Same problem as #5 in commerce-order.html.twig. I was able to get order_entity.getOrderNumber to work, though, so if anything, this should be documented in the twig file comments.

    In commerce_order.module, perhaps the order number needs to be explicitly added to the variables array in template_preprocess_commerce_order?

  • 🇮🇱Israel jsacksick

    {{ order.order_number }} should work if it's configured in the view mode. Have you tried that?

Production build 0.71.5 2024