FROM CACHE - en_header

Hot to get Automatic Discount object value?

Solved
IliaZ
Shopify Partner
11 3 0

Hi all,

 

I am attempting to dynamically get the automatic discount value of an Automatic Discount that is created within the discount section of admin. I then want to use that value to display a discounted price on my product and collection pages (for marketing reasons).

 

The logic would look something like this:

          {%- assign auto_discount = product.price | times: discount_application.automatic[0].value -%}
          {{ product.price | money }}, with discount 
          {{ product.price | minus: auto_discount | money }}

 

 
The above code does not work but I have branched off from an earlier ticket
 
Any thoughts?
 
Thanks in advance!
Accepted Solution (1)

Accepted Solutions
IliaZ
Shopify Partner
11 3 0

This is an accepted solution.

So I have finally figured this one out.

 

What i did is create a product metafield called auto_discount.

 

Then I went to a product and added my discount value to the metafield

 

Then I located my product block template (might be something else for you)

 

Then I created this code:

 

 

 {% if product.compare_at_price_max > product.price %}
        <span class="product-price__reduced theme-money">
          {{ product.price | money }}
        </span>
      {% else %}
        <span class="product-price__compare theme-money">
          Actual price: {{ product.price | money }}
        </span>
        <span> 
        |
        </span>
        <span class="product-price__reduced theme-money green">
          Discount percent: ( {{ product.metafields.my_fields.auto_discount.value }} )
        </span>
        <span class="product-price__reduced theme-money green">
          Discount Price:   
          {%- assign auto_discount = product.price | times: product.metafields.my_fields.auto_discount.value  -%}
          {{ product.price | minus: auto_discount | money }}
        </span>

 

 

You can see that I am multiplying my product.price x product.metafields.my_fields.auto_discount.value to get the discounted amount etc.

 

You will need to format this to suit your needs but the theory is the same.

 

Good luck!

 

P.S. go read up about metafields if you dont know what I am talking about

View solution in original post

Replies 2 (2)
IliaZ
Shopify Partner
11 3 0

A response in a previous thread describes using the metafields object to store the discount and retrieve it. See here

IliaZ
Shopify Partner
11 3 0

This is an accepted solution.

So I have finally figured this one out.

 

What i did is create a product metafield called auto_discount.

 

Then I went to a product and added my discount value to the metafield

 

Then I located my product block template (might be something else for you)

 

Then I created this code:

 

 

 {% if product.compare_at_price_max > product.price %}
        <span class="product-price__reduced theme-money">
          {{ product.price | money }}
        </span>
      {% else %}
        <span class="product-price__compare theme-money">
          Actual price: {{ product.price | money }}
        </span>
        <span> 
        |
        </span>
        <span class="product-price__reduced theme-money green">
          Discount percent: ( {{ product.metafields.my_fields.auto_discount.value }} )
        </span>
        <span class="product-price__reduced theme-money green">
          Discount Price:   
          {%- assign auto_discount = product.price | times: product.metafields.my_fields.auto_discount.value  -%}
          {{ product.price | minus: auto_discount | money }}
        </span>

 

 

You can see that I am multiplying my product.price x product.metafields.my_fields.auto_discount.value to get the discounted amount etc.

 

You will need to format this to suit your needs but the theory is the same.

 

Good luck!

 

P.S. go read up about metafields if you dont know what I am talking about