<p>I haven't done this myself, but I see two ways to get the percentage:</p>

<p>Take the <code>product.defaultVariant.saleAmount</code> and use maths in twig to work out the percentage - that should definitely work.  Twig math is a good general solution if you can't get the numbers you need directly from Commerce. See:</p>

<p><a href="http://twig.sensiolabs.org/doc/templates.html#math" rel="nofollow">http://twig.sensiolabs.org/doc/templates.html#math</a></p>

<p>However, I think you can use</p>

<pre><code> {% set sales = craft.commerce.getSales() %}
</code></pre>

<p>...to get all your SalesModels.</p>

<p>(see <code>/craft/plugins/commerce/models/Commerce_SaleModel.php</code>) as this model is not really documented yet it seems.</p>

<p>You'd loop through those and get the particular sale you're after (e.g. by <code>id</code>).  Then, it appears there is code in there to  <code>getDiscountAmountAsPercent</code> to get what you're after....however while <code>DiscountModel</code> has an attribute of <code>percentDiscount</code> on it, SaleModel does not appear to so I don't <em>think</em> you can get at it directly in your templates currently.</p>

<p>Unfortunately I am a bit pushed for time in terms of actually trying it to see.  But Twig maths will do it for sure if you get stuck with a more direct approach!</p>

CC BY-SA 3.0
2016-10-28T00:40:42.353Z
thanks a lot, i will try to figure it out tomorrow, i actually just need the value that the costumer enters to display something like a sticker on the product image to say how much % is off ..maybe there is a workaround if  the costumer just names the deal 20 for 20% and i can read out the deal name i.e.
HendrikEng
CC BY-SA 3.0
2016-10-28T00:41:43.827Z
will try to work it out and report here, thanks a lot :-)
HendrikEng
CC BY-SA 3.0
2016-10-28T00:38:15.677Z
2016-10-28T00:38:15.677Z
Jeremy Daalder
<p>For some reason the above answers aren't working for me, so I've done it the mathematical way...</p>

<p>Formula: ((newprice-oldprice)/oldprice)*100</p>

<p>In craft/twig code:</p>

<pre><code>{% if product.defaultVariant.onSale %}
  &lt;span class="badge"&gt;
    {% set procent = ((product.defaultVariant.salePrice-product.defaultPrice)/product.defaultPrice)*100 %}
    {{procent}}%
  &lt;/span&gt;
{% endif %}
</code></pre>

<p>Hope it helps for those who where struggling also... :)</p>

CC BY-SA 3.0
2017-06-08T21:48:41.063Z
2017-06-08T21:48:41.063Z
iDzine
<p>I believe <a href="https://craftcommerce.com/docs/line-item-model#saleamount" rel="nofollow">saleAmount</a> is what you're looking for.</p>

<pre><code>{% set amount = product.defaultVariant.saleAmount %}
</code></pre>

CC BY-SA 3.0
2016-10-28T00:36:23.963Z
i checked the docs again, i think you are right, i figured its saleAmount or discount but i cant cant it working, i want do output the value i entered in the dashboard (i.e. 20%) i updated the code above.
HendrikEng
CC BY-SA 3.0
2016-10-27T23:04:46.893Z
2016-10-28T00:06:34.630Z
2016-10-28T00:06:34.630Z
Brad Bell
<p>I am trying to display the Discount Value (%) of Products with the onSale Tag. What works for now is to display only the Products which are onSale. But I can't figure out which value stores the Discount Value.</p>

<pre><code>{% set products = craft.commerce.products.find() %} {% for product in products %}
&lt;li class="list-item"&gt;
    {% if product.defaultVariant.onSale == true %}
    &lt;div class="pin circle"&gt;
        &lt;h6&gt;Sale!&lt;/h6&gt;
        &lt;h6 class="percent"&gt;{{ amount.saleAmount }}/h6&gt;
        &lt;h6&gt;off&lt;/h6&gt;
    &lt;/div&gt;
    {% endif %}
</code></pre>

<p></li></p>

<templating><plugin-craftcommerce>
How can I display the Discount Value onSale of Products
# How can I display the Discount Value onSale of Products

(Asked by: username_0 on 2016-10-27)

I am trying to display the Discount Value (%) of Products with the onSale Tag. What works for now is to display only the Products which are onSale. But I can't figure out which value stores the Discount Value.
{% set products = craft.commerce.products.find() %} {% for product in products %}

    {% if product.defaultVariant.onSale == true %}
    
        Sale!
        {{ amount.saleAmount }}/h6>
        off
    
    {% endif %}

**Tags:** templating, plugin-craftcommerce

---

## 3 answers

### Answer by username_1 on 2016-10-28. Score: 2 | Accepted answer

I haven't done this myself, but I see two ways to get the percentage:
Take the product.defaultVariant.saleAmount and use maths in twig to work out the percentage - that should definitely work.  Twig math is a good general solution if you can't get the numbers you need directly from Commerce. See:
http://twig.sensiolabs.org/doc/templates.html#math
However, I think you can use
 {% set sales = craft.commerce.getSales() %}

...to get all your SalesModels.
(see /craft/plugins/commerce/models/Commerce_SaleModel.php) as this model is not really documented yet it seems.
You'd loop through those and get the particular sale you're after (e.g. by id).  Then, it appears there is code in there to  getDiscountAmountAsPercent to get what you're after....however while DiscountModel has an attribute of percentDiscount on it, SaleModel does not appear to so I don't think you can get at it directly in your templates currently.
Unfortunately I am a bit pushed for time in terms of actually trying it to see.  But Twig maths will do it for sure if you get stuck with a more direct approach!

> **Comments:**
> **username_0**: thanks a lot, i will try to figure it out tomorrow, i actually just need the value that the costumer enters to display something like a sticker on the product image to say how much % is off ..maybe there is a workaround if  the costumer just names the deal 20 for 20% and i can read out the deal name i.e.  
> **username_0**: will try to work it out and report here, thanks a lot :-)  

---

### Answer by username_2 on 2017-06-08. Score: 2

For some reason the above answers aren't working for me, so I've done it the mathematical way...
Formula: ((newprice-oldprice)/oldprice)*100
In craft/twig code:
{% if product.defaultVariant.onSale %}
  
    {% set procent = ((product.defaultVariant.salePrice-product.defaultPrice)/product.defaultPrice)*100 %}
    {{procent}}%
  
{% endif %}

Hope it helps for those who where struggling also... :)


---

### Answer by username_3 on 2016-10-27. Score: 1

I believe saleAmount is what you're looking for.
{% set amount = product.defaultVariant.saleAmount %}

> **Comments:**
> **username_0**: i checked the docs again, i think you are right, i figured its saleAmount or discount but i cant cant it working, i want do output the value i entered in the dashboard (i.e. 20%) i updated the code above.  

---

