【发布时间】:2021-11-19 19:03:30
【问题描述】:
我正在尝试在 Shopify 的购买后脚本中读取 Shopify 产品页面标签和 ID。
您无需熟悉 Shopify 即可了解我面临的这个问题。感觉是 Javascript 问题,我无法准确理解如何引用这些变量或对象。
请阅读 Shopify 的文档 here,了解我可以访问的变量。
我的代码
// Cart variables
var cartTagsString = "";
var cartProductIDString = "";
// Convert array of product tags into string
window.Shopify.order.lineitem.product.tags.forEach(function (item, index) {
cartTagsString = cartTagsString + item;
});
// Convert array of product id's into string
window.Shopify.order.lineitem.product.forEach(function (item, index) {
cartProductIDString = cartTagsString + item.id;
});
错误
“VM1370:44 Uncaught TypeError: Cannot read properties of undefined (reading 'product')”
转到发生错误的确切行,它会将我们带到这里:
window.Shopify.order.lineitem.product.tags
【问题讨论】:
标签: javascript shopify