使用Shopify购买按钮向网络应用的用户发布免费产品。需要确保用户最多只能订购1件商品。关于如何执行此操作的任何想法?
Shopify扩展程序是不行的,因为购买按钮不会加载它们。还对结帐链接进行了实验,这些链接将无法防止出现双重订单。
以下是“购买”按钮的代码:
<script type="text/javascript">
/*<![CDATA[*/
(function () {
var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/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: 'heavysoundlabs.myshopify.com',
storefrontAccessToken: '28703a091818546612d47f7c83047f6f',
});
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('product', {
id: '4713512665151',
node: document.getElementById('product-component-1598466400618'),
moneyFormat: '%24%7B%7Bamount%7D%7D',
options: {
"product": {
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "calc(25% - 20px)",
"margin-left": "20px",
"margin-bottom": "50px"
}
},
"title": {
"font-family": "PT Sans, sans-serif",
"font-weight": "normal"
},
"button": {
"font-family": "PT Sans, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
":hover": {
"background-color": "#e3ac00"
},
"background-color": "#fcbf00",
":focus": {
"background-color": "#e3ac00"
},
"padding-left": "14px",
"padding-right": "14px"
},
"quantityInput": {
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px"
},
"price": {
"font-family": "PT Sans, sans-serif"
},
"compareAt": {
"font-family": "PT Sans, sans-serif"
},
"unitPrice": {
"font-family": "PT Sans, sans-serif"
}
},
"buttonDestination": "checkout",
"contents": {
"img": false,
"title": false,
"price": false
},
"text": {
"button": "Get it now!"
},
"googleFonts": [
"PT Sans"
]
},
"productSet": {
"styles": {
"products": {
"@media (min-width: 601px)": {
"margin-left": "-20px"
}
}
}
},
"modalProduct": {
"contents": {
"img": false,
"imgWithCarousel": true
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "100%",
"margin-left": "0px",
"margin-bottom": "0px"
}
},
"button": {
"font-family": "PT Sans, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
":hover": {
"background-color": "#e3ac00"
},
"background-color": "#fcbf00",
":focus": {
"background-color": "#e3ac00"
},
"padding-left": "14px",
"padding-right": "14px"
},
"quantityInput": {
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px"
}
},
"googleFonts": [
"PT Sans"
],
"text": {
"button": "Add to cart"
}
},
"option": {
"styles": {
"label": {
"font-family": "PT Sans, sans-serif"
},
"select": {
"font-family": "PT Sans, sans-serif"
}
},
"googleFonts": [
"PT Sans"
]
},
"cart": {
"styles": {
"button": {
"font-family": "PT Sans, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
":hover": {
"background-color": "#e3ac00"
},
"background-color": "#fcbf00",
":focus": {
"background-color": "#e3ac00"
}
}
},
"text": {
"total": "Subtotal",
"button": "Checkout"
},
"googleFonts": [
"PT Sans"
]
},
"toggle": {
"styles": {
"toggle": {
"font-family": "PT Sans, sans-serif",
"background-color": "#fcbf00",
":hover": {
"background-color": "#e3ac00"
},
":focus": {
"background-color": "#e3ac00"
}
},
"count": {
"font-size": "14px"
}
},
"googleFonts": [
"PT Sans"
]
}
},
});
});
}
})();
/*]]>*/
</script>```
答案 0 :(得分:1)
您不能弄乱“购买”按钮。仅仅是在Shopify会话中获取变体ID,以便购物车可以处理该ID。您不能期望按钮实际上也包含业务逻辑。为此,您需要在Shopify内部进行工作。
答案 1 :(得分:0)
您可以寻求解决方法并创建一个折扣代码,该折扣代码为您提供特定产品的免费插件。您可以在其中设置一个限制,例如,每个客户只能使用一次折扣代码。