0

I have a use case that I need to add the retail price on a receipt twig next to the discounted unit price. Ive tried every possible field syntax I could think to try, looked everywhere and stumped...

{{ order_items.i_need_the_retail_price... }}

Is it possible to get that related field with twig syntax? It doesnt appear to be carried into Order Items.

11
  • Did you try dumping the variable? drupal.org/docs/8/theming/twig/…
    – anoopjohn
    Commented Jan 11, 2020 at 6:13
  • Ill give it a shot thank you.
    – Gregg
    Commented Jan 11, 2020 at 14:31
  • Using dump on the totals key gives me this data in an array: price (with the discount), percentage off, amount off etc all based on the entire line item though. The order_entity key hangs on a dump, can I drill down inside that dump somehow?
    – Gregg
    Commented Jan 11, 2020 at 16:53
  • Maybe just tell it to print 1-20 then I can try 21-40 etc? Im looking thru docs...
    – Gregg
    Commented Jan 11, 2020 at 17:11
  • You can inspect all the available variables inside the twig file and then use your logic to combine the numbers to get the result. Can't you?
    – anoopjohn
    Commented Jan 12, 2020 at 8:50

1 Answer 1

0

After a few more hours learning twig filters I can calculate the retail price in each line item with this:

{% for adjustment in totals.adjustments %}
{% set disc_percent_remainder = 1 - adjustment.percentage %}
{% set disc_unit_price_raw_2 = order_item.getUnitPrice|commerce_price_format %}
{% set disc_unit_price_raw_1 = disc_unit_price_raw_2|trim(' USD', 'right') %}
{% set disc_unit_price_raw = disc_unit_price_raw_1|trim('$', 'left') %}
{% set disc_unit_price = (disc_unit_price_raw * 100) / disc_percent_remainder %}
${{ (disc_unit_price / 100)|round(2, 'ceil') }}
{% endfor %}

This is a horrible work-around I'm sure, ruins any chance of multiple currencies and Im sure can be cleaned up a lot with nesting some of this. But, it comes up with the correct retail pice.

Your Answer

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

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