I want to add an product at the product page. I couldn’t do, if I did do like that page(https://shopify.dev/api/ajax/reference/cart).
my source is like that
const addUrl = window.Shopify.routes.root + 'cart/add.js';
export default class CartModel {
constructor() {
......
}
addProduct(btn) {
const toSend = {'items': [
id: xxxxxx,
quantity: 1
]};
fetch(addUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(toSend)
})
.then(response => {
....
})
.then(myBlob => {
.....
})
.catch((error) => {
......
});
}
}
but I got that error
Uncaught TypeError: Cannot read properties of undefined (reading 'routes')
before I could but now I cant. I have to include something?
Please tell me why.