我在我的页面上使用 Shopify 的购买按钮,我对此非常满意,但我需要添加创建“添加商品”的功能 - 这意味着当客户点击商品上的商品详细信息时,商品提供了该功能有一个附加项目。
很像这个插件:https ://spice-addons-demo.myshopify.com/collections/frontpage/products/the-sg-gems-necklace (我已经尝试实现它,没有运气)
如何使用购买按钮做到这一点?(此处的文档:http: //shopify.github.io/buy-button-js/,我尝试对其进行修改,但没有真正的运气)
这是我的代码:
/*<![CDATA[*/
(function () {
var scriptURL = 'js/buy-button-storefront.min.js';
if (window.ShopifyBuy) {
if (window.ShopifyBuy.UI) {
ShopifyBuyInit();
} else {
loadScript();
}
} else {
loadScript();
}
function loadScript() {
var script = document.createElement('script');
script.async = true;
script.src = scriptURL;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
script.onload = ShopifyBuyInit;
}
function ShopifyBuyInit() {
var client = ShopifyBuy.buildClient({
domain: 'xxx',
storefrontAccessToken: 'xxx',
});
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('collection', {
id: '230096961724',
node: document.getElementById('xxx'),
moneyFormat: '%24%7B%7Bamount%7D%7D',
options: {
"product": {
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "calc(33.33333% - 30px)",
"margin-left": "30px",
"margin-bottom": "50px",
"width": "calc(33.33333% - 30px)"
},
"img": {
"height": "calc(100% - 15px)",
"position": "absolute",
"left": "0",
"right": "0",
"top": "0"
},
"imgWrapper": {
"padding-top": "calc(75% + 15px)",
"position": "relative",
"height": "0"
}
},
"button": {
"font-weight": "bold",
"font-size": "18px",
"padding-top": "17px",
"padding-bottom": "17px",
":hover": {
"background-color": "#8b1a23"
},
"background-color": "#ca0027",
":focus": {
"background-color": "#8b1a23"
},
"border-radius": "7px",
"padding-left": "100px",
"padding-right": "100px"
},
"quantityInput": {
"font-size": "18px",
"padding-top": "17px",
"padding-bottom": "17px"
}
},
"buttonDestination": "modal",
"contents": {
"options": false
},
"text": {
"button": "View product"
}
},
"productSet": {
"styles": {
"products": {
"@media (min-width: 601px)": {
"margin-left": "-30px"
}
}
}
},
"modalProduct": {
"contents": {
"img": false,
"imgWithCarousel": true,
"button": false,
"buttonWithQuantity": true
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "100%",
"margin-left": "0px",
"margin-bottom": "0px"
}
},
"button": {
"font-weight": "bold",
"font-size": "18px",
"padding-top": "17px",
"padding-bottom": "17px",
":hover": {
"background-color": "#8b1a23"
},
"background-color": "#ca0027",
":focus": {
"background-color": "#8b1a23"
},
"border-radius": "7px",
"padding-left": "100px",
"padding-right": "100px"
},
"quantityInput": {
"font-size": "18px",
"padding-top": "17px",
"padding-bottom": "17px"
}
},
"text": {
"button": "Add to cart"
}
},
"cart": {
"styles": {
"button": {
"font-weight": "bold",
"font-size": "18px",
"padding-top": "17px",
"padding-bottom": "17px",
":hover": {
"background-color": "#8b1a23"
},
"background-color": "#ca0027",
":focus": {
"background-color": "#8b1a23"
},
"border-radius": "7px"
}
},
"text": {
"total": "Subtotal",
"button": "Checkout"
},
"popup": false
},
"toggle": {
"styles": {
"toggle": {
"font-weight": "bold",
"background-color": "#ca0027",
":hover": {
"background-color": "#8b1a23"
},
":focus": {
"background-color": "#8b1a23"
}
},
"count": {
"font-size": "18px"
}
}
}
},
});
});
}
})();
/*]]>*/