Since #2952529: Support for Layout Builder module is closed I don't think it's child issues will be noticed anymore. So hereby the 2 patches that are still preventing layout builder to work on orders.

Commerce ecosystem:

  • Make fields from referenced entities visible on parents (orders should be able to display shipping fields).
    • Either through hook_entity_extra_field_info() (Most modules already have the logic to add the variables during preprocessing, so this hook should suffice in many cases) . See comment #12 for details.
    • OR by making the whole linked entity available in layout builder, similar to how product variation fields are shown when editing a product

Commerce order:

State machine:

Commerce Shipping:

Comments

Neograph734 created an issue. See original summary.

neograph734’s picture

neograph734’s picture

Issue summary: View changes
abx’s picture

Not sure I should post in this or that sub issues but I already patched both patches and tested with lastest dev version. It didn't work. I can move around everything in Layout Builder for orders but nothing change when view it.

In order default view, once activated Layout Builder, this information is disappeared.
- Order Items
- "Customer Information" is there but there is nothing in that box.
- "Placed"
- "Changed"
- "Validate Order" Button
- "Cancel Order" Button

Also when, patch "State Machine", I got warning :

Checking patch src/Plugin/Field/FieldType/StateItem.php...
Applied patch src/Plugin/Field/FieldType/StateItem.php cleanly.
warning: 1 line adds whitespace errors.
abx’s picture

StatusFileSize
new142.04 KB
new158.38 KB
neograph734’s picture

abx that would make sense. The default order template does never render the entire order, only its individual fields.

Could you try changing commerce/modules/order/templates/commerce-order--admin.html.twig (assuming you are working on the admin view mode) and place {{ order }} somewhere in that template? That should render the order with layout builder enabled.

I suppose we need to find a way to make the fields layout use that template, but have layout builder use the commerce-order.html.twig template instead.

abx’s picture

Neograph734,

I tried to put {{ order }} in the commerce/modules/order/templates/commerce-order--admin.html.twig I, then, removed everything inside "Layout Builder" and found that the information that appear at first is there and has 2 copies of them. (image attached.)

I, then, tried to add "Order Items" in 2 Column layout in Layout Builder. Both of them appear. (Image attached.)

abx’s picture

abx’s picture

I can't delete image that I uploaded though.

Just play around with Layout Builder and what I noticed that some options are not available in Layout Builder. (All the information that show twice in the image and some others.)

These are what I don't see in the option list.
- Order Activity
- Shipping Information
- Shipping Method
- Subtotal
- Shipping Fee
- Validate Order Button
- Cancel Order Button
- Unit Price, Quantity and Total Price

neograph734’s picture

To give you the best control, I think you should change the twig template to only contain {{ order }}. The reason you see double fields is because of the item being rendered as part of {{order}} but also individually as {{order.field_name}}.

I'll have a look at the fields you're missing later this week. It could be a known issue in core. Could you try disabling layout builder, then place the missing fields into the enabled section and then turn layout builder back on. Do they show then?

abx’s picture

StatusFileSize
new212.08 KB

I play around with it for a bit and got an update for missing fields below:

  1. Order Activity - Missing
  2. Shipping Information (Shipping Address) - Missing
  3. Shipping Method - Missing
  4. Subtotal, Shipping Fee, Total -> "Total price" field with "Formatter" set as "Order Total Summary"
  5. Validate Order Button, Cancel Order Button -> "State" field with "Formatter" set as "Transition form"
  6. Unit Price, Quantity and Total Price -> "Order item" field with "Formatter" set as "Order item table"

1 - 3 are fields that always display when enable Layout Builder and I couldn't find any option in Both with/without Layout builder. (Attached image with normal field list without Layout builder.)

neograph734’s picture

Issue summary: View changes

Thanks abx, for taking the time to look around and pinpoint the missing items.

I've played around and got the shipping information to show (with 2 profiles though... ?) by using the following hook in commerce_shipping:

/**
 * Implements hook_entity_extra_field_info().
 */
function commerce_shipping_entity_extra_field_info() {
  $return = [];
  foreach (OrderType::loadMultiple() as $order_type) {
    $return['commerce_order'][$order_type->id()]['display']['shipping_information'] = [
      'label' => t('Shipping information'),
      'weight' => 100,
      'visible' => TRUE,
    ];
  }
  return $return;
}

For commerce activity, not tested, but simply looking at commerce_log_preprocess_commerce_order I'd assume the exact same hook should work:

// Add this to the top.
use Drupal\commerce_order\Entity\OrderType;


/**
 * Implements hook_entity_extra_field_info().
 */
function commerce_log_entity_extra_field_info() {
  $return = [];
  foreach (OrderType::loadMultiple() as $order_type) {
    $return['commerce_order'][$order_type->id()]['display']['activity'] = [
      'label' => t('Order activity'),
      'weight' => 100,
      'visible' => TRUE,
    ];
  }
  return $return;
}

Though I've also seen how fields from linked entities can be shown in the layout builder. (eg. product variation field when editing a product.). I just have no idea about the complexity of that.
Updated the issue summary with both options.

neograph734’s picture

Issue summary: View changes
neograph734’s picture

Issue summary: View changes
neograph734’s picture

Issue summary: View changes
neograph734’s picture