I'm toying with developing a Shopify App that uses the DaisyAPI dynamic image service for Shopify. In order to make the correct call to the Daisy API, I need to know what Product the customer is looking at. It seems like, to reliably do that, I will need to manipulate their product.liquid theme to insert a hidden value containing the Product ID so that Jquery can pick up that value and insert it into the API call.
What's the best way to ensure every product page contains the product ID in such a way jQuery can reliably find it? Am I overlooking something obvious?
Many thanks!
In order to get started with using Product JSON in Shopify, you will first need to create a private app. You can create a private app by going to the Apps section of your Shopify admin, and then selecting the Manage private apps link. Once you have created your private app, you will be given a API key and API password.
In your Shopify Admin, go to Products and choose the product you want. The product_id is the number string at the end of the URL.
Another option would be to use the Ajax API to request the product. Of you know you're on a product page simple make a request to the same URL and append .json. You will then have a json representation of the product that you can do whatever yo want with.
To get you js into the theme you can use a script tag which will load js from you server onto the shop.
You are missing a very obvious and cool Liquid filter.
In Liquid, pump the Object for it's JSON.
var p = {{ product | json }};
And then go to town... you cannot go far on the client without this concept. Get the JSON man.. get the JSON...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With