Get current product id using Shopify API to invoke Javascript API

I play with the development of the Shopify application, which uses the DaisyAPI dynamic image service for Shopify. To make the correct Daisy API call, I need to know which product the client belongs to. It seems that having done this securely, I will need to manipulate my product.liquid theme to insert a hidden value containing the product identifier so that JQuery can get that value and insert it into the API call.

What is the best way to ensure that each product page contains a product identifier so that jQuery can reliably find it? Can I ignore something obvious?

Many thanks!

+6
source share
2 answers

You are missing a very clear liquid filter.

In Liquid, upgrade the object for it JSON.

var p = {{ product | json }}; 

And then go to the city ... you cannot go far on a client without this concept. Get JSON people .. get JSON ...

+10
source

Another option is to use the Ajax API to request the product. You know that you on the product page just make a request to the same URL and add .json. After that, you will have a json representation of the product, which you can do no matter what you want.

To get js in the topic, you can use a script tag that will load js from your server to the store.

+7
source

Source: https://habr.com/ru/post/923714/


All Articles