| 794 |
rajveer |
1 |
var totalAmount=0.00;
|
|
|
2 |
$(document).ready(function(){
|
|
|
3 |
$('#cartTable td img.remove-quantitybttn').click(function(){
|
|
|
4 |
var prodID = $(this).parent().parent().children().find("span.pro").attr("id");
|
|
|
5 |
/*
|
|
|
6 |
Put Ajax call here
|
|
|
7 |
To write the way to get itemid to be removed
|
|
|
8 |
alert("Product with id " + prodID + " will be removed.");
|
|
|
9 |
*/
|
|
|
10 |
//alert("AJAX request to remove products from Cart. Product ID: " + prodID);
|
|
|
11 |
jQuery.ajax({
|
|
|
12 |
type: "GET",
|
|
|
13 |
url: "/cart/" + prodID + "?_method=delete",
|
|
|
14 |
data: "productid="+prodID,
|
|
|
15 |
success: function(msg){
|
|
|
16 |
//alert( "Data Saved: " + msg );
|
|
|
17 |
if(msg==1){
|
|
|
18 |
// alert( "Deleted the item" );
|
|
|
19 |
}else{
|
|
|
20 |
// alert( "Not able to deleted the item" );
|
|
|
21 |
return;
|
|
|
22 |
}
|
|
|
23 |
window.location.reload();
|
|
|
24 |
}
|
|
|
25 |
});
|
|
|
26 |
var $tr = $(this).parent().parent();
|
|
|
27 |
var index = $tr.parent().children().index($tr);
|
|
|
28 |
$(this).parent().parent().remove();
|
|
|
29 |
var totalAmount=subtractionOfColumns("cartTable", 5, true);
|
|
|
30 |
$("#totalAmount").html(totalAmount);
|
|
|
31 |
});
|
|
|
32 |
});
|
|
|
33 |
|
|
|
34 |
function changeQty(obj,itempriceID,totalPriceID) {
|
|
|
35 |
var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
|
|
|
36 |
var quantity = parseInt(obj.value)
|
|
|
37 |
//alert("AJAX request to change product quantity in Cart. Product ID: " + prodID + " quantity: " + quantity);
|
|
|
38 |
|
|
|
39 |
jQuery.ajax({
|
|
|
40 |
type: "POST",
|
|
|
41 |
url: "/cart/" + prodID + "?_method=put&productid="+prodID+ "&quantity="+quantity,
|
|
|
42 |
data: "productid="+prodID+ "&quantity="+quantity,
|
|
|
43 |
success: function(msg){
|
|
|
44 |
// alert( "Data Saved: " + msg );
|
|
|
45 |
if(msg==1){
|
|
|
46 |
// alert( "Quantity Updates for the item" );
|
|
|
47 |
}else{
|
|
|
48 |
// alert( "Not able to update the quantity for the item" );
|
|
|
49 |
return;
|
|
|
50 |
}
|
|
|
51 |
window.location.reload();
|
|
|
52 |
}
|
|
|
53 |
});
|
|
|
54 |
|
|
|
55 |
var val=document.getElementById(itempriceID).value;
|
|
|
56 |
var num = parseFloat(val.replace(/[^\d\.-]/g,''));
|
|
|
57 |
var qty=parseInt(obj.value);
|
|
|
58 |
var totalVal1=num*qty;
|
|
|
59 |
var formated_value = $().number_format(totalVal1, {
|
|
|
60 |
numberOfDecimals:2,
|
|
|
61 |
decimalSeparator: '.',
|
|
|
62 |
thousandSeparator: ',',
|
|
|
63 |
symbol: 'Rs. '
|
|
|
64 |
});
|
|
|
65 |
document.getElementById(totalPriceID).innerHTML=formated_value;
|
|
|
66 |
$("#totalAmount").html(sumOfColumns("cartTable", 5, true));
|
|
|
67 |
|
|
|
68 |
changeEstimate(prodID);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
function sumOfColumns(tableID, columnIndex, hasHeader) {
|
|
|
72 |
var tot = 0;
|
|
|
73 |
var inc=1;
|
|
|
74 |
$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
|
|
|
75 |
.children("td:nth-child(" + columnIndex + ")")
|
|
|
76 |
.each(function() {
|
|
|
77 |
var currentVal=document.getElementById('totalPrice'+inc).innerHTML;
|
|
|
78 |
inc++;
|
|
|
79 |
var splitVal=currentVal.split("Rs.");
|
|
|
80 |
var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
|
|
|
81 |
tot += parseFloat(num);
|
|
|
82 |
});
|
|
|
83 |
totalAmount=tot;
|
|
|
84 |
var formated_value = $().number_format(tot, {
|
|
|
85 |
numberOfDecimals:2,
|
|
|
86 |
decimalSeparator: '.',
|
|
|
87 |
thousandSeparator: ',',
|
|
|
88 |
symbol: 'Rs.'
|
|
|
89 |
});
|
|
|
90 |
return formated_value;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
|
|
|
94 |
var tot = 0;
|
|
|
95 |
$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
|
|
|
96 |
.children("td:nth-child(" + columnIndex + ")")
|
|
|
97 |
.each(function() {
|
|
|
98 |
var currentVal=$(this).html();
|
|
|
99 |
var splitVal=currentVal.split("Rs.");
|
|
|
100 |
var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
|
|
|
101 |
tot += parseInt(num);
|
|
|
102 |
});
|
|
|
103 |
var formated_value = $().number_format(tot, {
|
|
|
104 |
numberOfDecimals:2,
|
|
|
105 |
decimalSeparator: '.',
|
|
|
106 |
thousandSeparator: ',',
|
|
|
107 |
symbol: 'Rs.'
|
|
|
108 |
});
|
|
|
109 |
return formated_value;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
function changeEstimate(item_id) {
|
|
|
113 |
if(item_id == null ){
|
|
|
114 |
// alert("item id is null");
|
|
|
115 |
for(var i=0; ; i++){
|
|
|
116 |
|
|
|
117 |
var obj = $("#itemID"+(i+1));
|
|
|
118 |
var itemId = $(obj).parent().find("span.pro").attr("id");
|
|
|
119 |
// alert("item id is " + itemId);
|
|
|
120 |
if(itemId == null){
|
|
|
121 |
break;
|
|
|
122 |
}
|
|
|
123 |
changeEstimate(itemId)
|
|
|
124 |
}
|
|
|
125 |
}else{
|
|
|
126 |
jQuery.ajax({
|
|
|
127 |
type: "GET",
|
|
|
128 |
url: "/estimate/"+$("#zipcode").val()+"_"+item_id,
|
|
|
129 |
beforeSend: function(){
|
|
|
130 |
$("#days"+"_"+item_id).html("<img src='/images/loader_l.gif'>");
|
|
|
131 |
},
|
|
|
132 |
success: function(msg){
|
|
|
133 |
// alert( "delivery estimate is " + msg);
|
|
|
134 |
$("#shipping_time"+"_"+item_id).html(msg);
|
|
|
135 |
}
|
|
|
136 |
});
|
|
|
137 |
}
|
|
|
138 |
}
|