Add product in cart by using Shopify
I have a product based Website build in WordPress, i have used shopify for add to cart, but having some issue to add multipal products.
i am using this script for add to cart
function buyButtonClickHandler(evt) {
evt.preventDefault();
evt.stopImmediatePropagation();
var id = product.selectedVariant.id;
var id = evt.target.id;
var quantity;
var cartLineItem = findCartItemByVariantId(id);
quantity = cartLineItem ? cartLineItem.quantity + 1 : 1;
addOrUpdateVariant(product.selectedVariant, quantity);
setPreviousFocusItem(evt.target);
$('#checkout').focus();
}
this use for update quantity for products
function updateQuantity(fn, variantId) {
var variant = product.variants.filter(function (variant) {
return (variant.id === variantId);
})[0];
var quantity;
var cartLineItem = findCartItemByVariantId(variant.id);
if (cartLineItem) {
quantity = fn(cartLineItem.quantity);
updateVariantInCart(cartLineItem, quantity);
}
}
Any buddy have an idea please help.
I have fount solution of these issue
to add single or multi-pal product on 'add to cart' we have use this
$('.cart').on('click', '.quantity-increment', function(event) {
var variantId = $(this).data('variant-id');
console.log(variantId);
incrementQuantity(variantId);
event.preventDefault();
});
$('.cart').on('click', '.quantity-decrement', function(event) {
var variantId = $(this).data('variant-id');
decrementQuantity(variantId);
event.preventDefault();
});
function decrementQuantity(variantId) {
updateQuantity(function(quantity) {
return quantity - 1;
}, variantId);
}
function incrementQuantity(variantId) {
updateQuantity(function(quantity) {
return quantity + 1;
}, variantId);
}
链接地址: http://www.djcxy.com/p/93014.html
上一篇: 使用自定义域名的Firebase托管服务拥有指向firebase.com的SSL证书
下一篇: 使用Shopify将产品添加到购物车中