Score:1

How do I render a commerce promotion coupon code on the order details?

gg flag

I want to show a coupon code used on an order details page, but cannot seem to render it on a templates. Here are some things I have tried so far...

{% for coupon in order_entity.coupons %}
  {{ coupon.target_id }}
  {{ coupon.code }}
  {{ drupal_entity('commerce_promotion_coupon', coupon.target_id) }}
  {{ drupal_field('code', 'commerce_promotion_coupon', coupon.target_id) }}
{% endfor %}

The only thing that works is {{ coupon.target_id }} and it just prints out the id as a number. I thought I could use Twig Tweak to load the entity and get it that way, but that doesn't seem to work either.

Thanks!

au flag
Try to inspect the ID variable to make sure it contains an ID not render array. `{{ dd(coupon.target_id) }}`
Score:0
gg flag

How I solved it ... (requires Twig Tweak module)

{% set coupon_entity = drupal_entity('commerce_promotion_coupon', coupon.target_id) %}
{{ coupon_entity['#commerce_promotion_coupon'].getCode }}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.