Hello How can I get a product ID and set it in the fetch solution in the ID field: 'id':
What would be the code to insert in that area?
$("#purchase").click(function(){
var addData = {
'id':, /* ID Variant */
'quantity':1
};
fetch('/cart/add.js', {
body: JSON.stringify(addData),
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-Requested-With':'xmlhttprequest',
},
method: 'POST'
}).then(function(response) {
return response.json();
}).then(function(json) {
/* we have JSON */
console.log(json)
}).catch(function(err) {
/* uh oh, we have error. */
console.error(err)
});
});
you should to add Attribute with name variant-id to the #purchase button you don't need for the product_id to add the item to the cart and get the variant id by document.getElementById('purchase').getAttribute("variant-id ");
and in the button #purchase <button id='purchase' variant-id={{variant.id}} >