-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmultify.js.liquid
More file actions
63 lines (57 loc) · 1.9 KB
/
Copy pathmultify.js.liquid
File metadata and controls
63 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script>
var length = {{ product.variants.size }};
$(window).on('load', function() {
$('.table-quantity').change(function () {
var price = $(this).parent().attr('data-price');
var price = Shopify.formatMoney(price, "");
var id = $(this).parent().attr("id");
id = id.split("-");
var selector = id[0];
});
$("#submit-table").click(function(e) {
e.preventDefault();
$('#AddToCartText').text('Adding...').parent().css('background-color','orange');
var toAdd = new Array();
for(i=0; i < length; i++){
console.log($(".item-"+ i +' div').attr('value'));
toAdd.push({
quantity: $(".item-"+ i +" .table-quantity").val(),
id: $(".item-"+ i +' div').attr("id").split("-")[0]
});
}
console.log("test:" + toAdd);
function moveAlong(){
if (toAdd.length) {
var request = toAdd.shift();
var tempId= request;
console.log(tempId);
var params = {
type: 'POST',
url: '/cart/add.js',
data: tempId,
dataType: 'json',
success: function(line_item) {
console.log("success!");
moveAlong();
},
error: function() {
console.log("fail");
}
};
$.ajax(params);
} else {
$('.quantity-dropdown').val(0);
$('.table-quantity').val(0);
$('#AddToCartText').text('Added!').parent().css('background-color','green');
setTimeout(function(){
$('#AddToCartText').text('Add To Cart').parent().css('background-color','black');
},3000);
jQuery.getJSON('/cart.js', function(cart) {
$('#CartCount').text(cart.item_count);
});
}
};
moveAlong();
});
});
</script>