Solved

Lowest price last 30 days

GesSan
Shopify Partner
3 0 0

Is there a way to code a variable with liquid to keep track of a product price and then display the lowest price of that product for the last 30 days without using an app? This has become a requirement for my store since the European Pricing Indication Directive:

https://help.shopify.com/en/manual/compliance/legal/pricing-indication-directive

 

I have a lot of products in my store and I do not have the time to do it manually for each product by the "compare at price" method or using metafields. Unless there is a way of inserting such a dynamic variable into a metafield.

And from what I've seen there are only paid apps that do this, which I would like to avoid if possible.

 

Any suggestions would be much appreciated.

 

Accepted Solution (1)

Liam
Shopify Staff
2731 298 769

This is an accepted solution.

Hi GesSan,

 

There is currently no way to use Liquid to dynamically display the lowest price of a product, updating over the 30 day window. You could explore creating your own custom app to achieve this. The general process would be:

  • Set up a product/update webhook to listen for price changes 
  • Create a database to store historical product price data, where you'd record product ID, the price at the time of the update, and the timestamp of when the update occurred
  • Set up a scheduled task to calculate the lowest price of a product over the last 30 days. 
  • Create a custom API endpoint to provide the lowest price data for a given product. This endpoint will query your database to find the lowest price within the past 30 days and return it in the response.
  • On the product page, use JavaScript to make an AJAX call to your backend endpoint and retrieve the lowest price.
  • Update the page's DOM with this information, so the user sees the lowest price dynamically.

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

Liam
Shopify Staff
2731 298 769

This is an accepted solution.

Hi GesSan,

 

There is currently no way to use Liquid to dynamically display the lowest price of a product, updating over the 30 day window. You could explore creating your own custom app to achieve this. The general process would be:

  • Set up a product/update webhook to listen for price changes 
  • Create a database to store historical product price data, where you'd record product ID, the price at the time of the update, and the timestamp of when the update occurred
  • Set up a scheduled task to calculate the lowest price of a product over the last 30 days. 
  • Create a custom API endpoint to provide the lowest price data for a given product. This endpoint will query your database to find the lowest price within the past 30 days and return it in the response.
  • On the product page, use JavaScript to make an AJAX call to your backend endpoint and retrieve the lowest price.
  • Update the page's DOM with this information, so the user sees the lowest price dynamically.

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

GesSan
Shopify Partner
3 0 0

Thank you Liam. Unfortunately I have no idea how to go about creating a custom Shopify app. And I would need to learn JavaScript as well.  A lot of work for a relatively simple task. I am just starting out my journey to learn programming and I don't know exactly what each bullet point means. But the little I do know tells me that your solution would work. Nevertheless two very naive questions come to mind.

Where would I store the database?

How would I go about the last point?

Update the page's DOM with this information, so the user sees the lowest price dynamically.

 

Also I would like to know if Shopify is working towards creating such an app, preferably free. Since it has become a lawful requirement in the EU, which is not a small market (maybe not the major ones for Shopify currently, but I expect it to be one of the largest sooner or later).

Anyway, for now it seems I'll have to settle for doing the price history manually or choosing to pay for an app.

 

Thanks again for the detalied reply,

Have a great day,

Best Regards