Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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) => { ...... }); } }
Uncaught TypeError: Cannot read properties of undefined (reading 'routes')before I could but now I cant. I have to include something?
change
const addUrl = window.Shopify.routes.root + 'cart/add.js';
to
const addUrl = '/cart/add.js';
I could. Is it the solution?
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025