Multiple variant quantity inputs to cart
Shopify.itemsToAdd = [];
Shopify.addItemstoTheCart = function() {
if (Shopify.itemsToAdd.length) {
var item = Shopify.itemsToAdd.pop();
$.ajax({
url: '/cart/add',
dataType: 'json',
type: 'post',
data: item,
success: Shopify.addItemstoTheCart,
error: Shopify.addItemstoTheCart
});
}
else {
window.location.href = '/cart';
}
};
$(function(){
$('#AddToCartText').click(function(event){
event.preventDefault();
Shopify.itemsToAdd = [];
$('.quantity-selector').each(function() {
console.log($(this).attr('data-id'));
var quantity = parseInt($(this).val(), 10);
if (quantity) {
Shopify.itemsToAdd.push( { id: $(this).attr('data-id'), quantity: quantity } );
}
});
if (Shopify.itemsToAdd.length) {
Shopify.addItemstoTheCart();
}
});
});