Commerce: Show quantity discounts starting point

I have the following offer with quantity discounts for a series of my products:


Buy 1 item and get $5 off per item
Buy 2 items and get $10 off per item
Buy 3 items and get $15 off per item


I set these discount rules in my control panel under "commerce" > "promotions".



product template

Now in my product template, I would like to be able to output (for each quantity level):


the normal (non-discounted) price
the discounted price
savings in terms of $
savings in terms of %




example

For example it would then say on the product page (output):


  "If you buy 2 items, you only pay $[discount price for 2 items]
  instead of $[normal price] per item. So your total today is only
  $[2 x discount price for 2 items] insted of $[2 x normal price].
  You therefore save $[(2 x normal price)-(2 x discount price for 2
  items)]. That's a discount of […]%."


The same goes for the discount offer of ordering 1 item or 3 items.



How can I accomplish this with all the discounts and math operations involved?
What have you tried so far?

The documentation seems to be missing, but looking at /craft/plugins/commerce/models/Commerce_DiscountModel.php you can find the properties purchaseQty and perItemDiscount that you need for the calculations.

{% for prod in product.variants %}
   {% for discount in craft.commerce.discounts %}
      {% set totalPrice = (discount.purchaseQty * prod.price) %}
      {% set totalDiscountPrice = (discount.purchaseQty * (prod.price + discount.perItemDiscount)) %}
      {% set totalDiscount = (totalPrice-totalDiscountPrice) %}
      {% set totalDiscountPercent = (totalDiscount/totalPrice)*100 %}

      &lt;p&gt;If you buy {{ discount.purchaseQty }} items, you only pay {{ totalDiscountPrice|currency(cart.currency) }} instead of {{ prod.price|currency(cart.currency) }} per item. So your total today is only {{ totalDiscountPrice|currency(cart.currency) }} insted of {{ totalPrice|currency(cart.currency) }}. You therefore save {{ totalDiscount|currency(cart.currency) }}. That's a discount of {{ totalDiscountPercent|round }}%.&lt;/p&gt;
   {% endfor %}
{% endfor %}


This will show all of the discounts for all of the products. You will need to modify it slightly if you have specified the discount for a specific product. You also need to check if the discount is enabled or not using discount.enabled