I've faced with task when I need to display different information from product and purchased entity for order items in cart block, cart page, checkout pages. I've several order items types and different view modes. I haven't find any templates for order items. So I decided to create patch and add theme suggestions as Drupal Commerce does for it's other entities.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

khiminrm created an issue. See original summary.

khiminrm’s picture

khiminrm’s picture

Status: Active » Needs review

Status: Needs review » Needs work
khiminrm’s picture

Status: Needs work » Needs review
FileSize
2.83 KB
khiminrm’s picture

bojanz’s picture

Status: Needs review » Needs work

No reason not to add this template.

Problems:

1. We don't prefix our entities and render arrays with commerce_ in templates. So we want just order_item and order_item_entity.

2.

+  $purchased_entity = $commerce_order_item->getPurchasedEntity();
+  $variables['purchased_entity'] = $purchased_entity;
+  $product = $purchased_entity->getProduct();
+  $variables['product_entity'] = $product;

I don't think we should do this. The template can easily do {{ order_item_entity.getPurchasedEntity.getProduct.something }} when needed.

khiminrm’s picture

@bojanz, thanks for your help!

I've created new patch using your suggestions.

khiminrm’s picture

Status: Needs work » Needs review
Niklan’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.39 KB

Thank you for the provided patch.

The patch works as expected, but there is a mistake made in #8. The theme variables became "order_item" but in template still used "commerce_order_item". So, I changed in patch #8 and sure it can be marked as RTBC.

diff -u b/modules/order/templates/commerce-order-item.html.twig b/modules/order/templates/commerce-order-item.html.twig
--- b/modules/order/templates/commerce-order-item.html.twig
+++ b/modules/order/templates/commerce-order-item.html.twig
@@ -23,3 +23,3 @@
 <div{{ attributes }}>
-  {{- commerce_order_item -}}
+  {{- order_item -}}
 </div>
Martijn de Wit’s picture

Status: Reviewed & tested by the community » Needs work

Both patches don't apply any more.

alex.stanciu’s picture

alex.stanciu’s picture

alex.stanciu’s picture

Status: Needs work » Reviewed & tested by the community

Patch now applies cleanly, moving back to RTBC

majmunbog’s picture

Confirming the patch #13 works fine.

  • mglaman committed fbdea2d on 8.x-2.x authored by alex.stanciu
    Issue #3009602 by khiminrm, alex.stanciu, Niklan, Martijn de Wit, bojanz...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! 🥳 commited.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.