How can I loop through the field on the front-end to get the qty and prices?
terryupton opened this issue · 3 comments
terryupton commented
I would like to show a table for the qty's and the prices for each bulk qty as per what is setup in the backend. How can I loop through this on the front-end?
I have tried a few approaches, but hitting errors:
Key "qty" for array with keys "iso, 2, 4" does not exist.
{% for column in purchasable.setDiscounts %}
{{ column.qty }}
{% endfor %}
Array to string conversion
{% for column in purchasable.setDiscounts %}
{{ column }}
{% endfor %}
terryupton commented
This has got me most of the way there...
{% for col in purchasable.setDiscounts.GBP %}
{# {{ col[0] }} - {{ col[1] }}#}
{{ col }}
{% endfor %}
{% for key, value in purchasable.setDiscounts.GBP %}
Key : {{ key }}
Value : {{ value }}
{% endfor %}
terryupton commented
Final update:
{% for purchasable in product.variants %}
{{ purchasable.title }}<br />
{{ purchasable.price|commerceCurrency(cart.currency) }}<br />
{% for qty, price in purchasable.setDiscounts.GBP|slice(1) %}
Qty : {{ qty }}
Price : {{ price|number_format(2, '.', ',')|commerceCurrency(cart.currency) }}
<br />
{% endfor %}<br /></br />
{% endfor %}
samuelbirch commented
{% for qty, price in purchasable.bulkPricesField[cart.paymentCurrency] if key != 'iso' %}
Qty: {{ qty }}
Price: {{ price|commerceCurrency(cart.paymentCurrency) }}
{% endfor %}