使用自定义链接将产品添加到购物车,而不直接添加到Cart.php



Big Commerce没有本地集成,不允许在总额中添加固定费用,所以我想在我的产品页面上添加一个额外的按钮,使用产品id将固定费率产品添加到购物车中。我发现我可以做到这一点(https://support.bigcommerce.com/s/article/How-can-I-add-a-product-to-the-cart-with-a-link?language=en_US#add-到购物车(,我使用这个链接:<a href="/cart.php?action=add&sku=5016" class="button button--green coa-btn">Add Certificate of Analysis (+$25)</a>将产品添加到购物车中,但理想情况下,我希望留在该产品页面上,而不是重定向到购物车页面。关于如何解决这个问题,有什么建议吗?

要回答您的问题,您可以使用Storefront Cart API添加产品,或向add To Cart URL发出提取请求。看见https://developer.bigcommerce.com/api-docs/storefront/add-to-cart-urls#adding-多种产品https://developer.bigcommerce.com/api-reference/storefront/carts

另一个选项是使用模具utils-itemAdd函数(utils.api.cart.itemAdd(https://developer.bigcommerce.com/stencil-docs/reference-docs/stencil-utils-api-reference#cart-api

但是,在您的情况下,将证书作为产品选项添加可能更简单。还是这条路线不适合你?

编辑:运行脚本以添加产品并且不去任何地方:

$('button#addToCart').on('click', () =>
$.get('/cart.php?action=add&sku=5016')
.done((data, status) => {
// do something here if you want
console.log(`first item complete with status ${status}`);
}));

最新更新