| 17804 |
manish.sha |
1 |
function loadCartPageDetails(){
|
| 17832 |
manish.sha |
2 |
var payable = $('div.cartgrandtotal span.pull-right').text().split(" ");
|
|
|
3 |
payable = payable[2];
|
|
|
4 |
if(parseInt(payable)>0){
|
|
|
5 |
$('button.checkoutbtn').prop( "disabled", false );
|
|
|
6 |
}else{
|
|
|
7 |
$('button.checkoutbtn').prop( "disabled", true );
|
|
|
8 |
}
|
| 17881 |
manish.sha |
9 |
var estimateString = $('div.popover-markup').data('str');
|
|
|
10 |
if(estimateString!="Can't ship here"){
|
|
|
11 |
$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {
|
|
|
12 |
$(this).prop('disabled', false);
|
|
|
13 |
});
|
|
|
14 |
var cart_details = localStorage.getItem('cart_details');
|
|
|
15 |
|
|
|
16 |
localStorage.removeItem('cart_details');
|
| 17911 |
manish.sha |
17 |
if(cart_details!=undefined){
|
|
|
18 |
var totalCartValue = 0;
|
|
|
19 |
var totalCartQuantity = 0;
|
|
|
20 |
var cartItems = {};
|
|
|
21 |
var jsonObjToBeStored = {};
|
|
|
22 |
var shippingCharges = 0;
|
|
|
23 |
var totalSkus = 0;
|
|
|
24 |
|
|
|
25 |
totalCartValue = $('.cartitemstotal').data('itemtotal');
|
|
|
26 |
shippingCharges = $('.cartitemstotal').data('shipping');
|
|
|
27 |
|
|
|
28 |
$('.number-spinner').each(function (index, val) {
|
|
|
29 |
var element = $(val);
|
|
|
30 |
var quantity = element.find("input").val();
|
|
|
31 |
if(parseInt(quantity)>0){
|
|
|
32 |
var sku = element.find("button[data-dir='up']").data('id');
|
|
|
33 |
var price = element.find("button[data-dir='up']").data('price');
|
|
|
34 |
|
|
|
35 |
var prodname = $(this).data('name');
|
|
|
36 |
var brandname = $(this).data('brand');
|
|
|
37 |
var itemDetail = {};
|
|
|
38 |
totalCartQuantity = totalCartQuantity + parseInt(quantity);
|
|
|
39 |
totalSkus = totalSkus +1;
|
|
|
40 |
itemDetail['quantity']=parseInt(quantity);
|
|
|
41 |
itemDetail['unitprice']=parseInt(price);
|
|
|
42 |
itemDetail['productname']=prodname;
|
|
|
43 |
itemDetail['brand']=brandname;
|
|
|
44 |
cartItems[sku.toString()]=itemDetail;
|
|
|
45 |
}
|
|
|
46 |
});
|
|
|
47 |
|
|
|
48 |
jsonObjToBeStored['totalCartQuantity'] = totalCartQuantity;
|
|
|
49 |
jsonObjToBeStored['totalCartValue'] = totalCartValue;
|
|
|
50 |
jsonObjToBeStored['cartItems'] = cartItems;
|
|
|
51 |
jsonObjToBeStored['shippingCharges'] = shippingCharges;
|
|
|
52 |
jsonObjToBeStored['totalSkus'] = totalSkus;
|
|
|
53 |
localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));
|
|
|
54 |
}
|
| 17881 |
manish.sha |
55 |
}else{
|
|
|
56 |
$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {
|
|
|
57 |
$(this).prop('disabled', true);
|
|
|
58 |
});
|
|
|
59 |
}
|
| 17905 |
manish.sha |
60 |
if(!$('div.cartitemstotal').hasClass('hidden')){
|
|
|
61 |
$('div.scroll').attr('style', 'margin-bottom: 155px');
|
|
|
62 |
}else{
|
|
|
63 |
$('div.scroll').attr('style', 'margin-bottom: 100px');
|
|
|
64 |
}
|
| 17804 |
manish.sha |
65 |
}
|
|
|
66 |
|
|
|
67 |
$(function(){
|
|
|
68 |
loadCartPageDetails();
|
|
|
69 |
});
|
|
|
70 |
|
|
|
71 |
$(document).on('click','.number-spinner button',function(){
|
|
|
72 |
btn = $(this);
|
|
|
73 |
input = btn.closest('.number-spinner').find('input');
|
|
|
74 |
oldValue = btn.closest('.number-spinner').find('input').val().trim(),
|
|
|
75 |
newVal = 0;
|
|
|
76 |
btn.closest('.number-spinner').find('button').prop("disabled", false);
|
|
|
77 |
var totalCartQuantity = 0;
|
|
|
78 |
var totalCartValue = 0;
|
|
|
79 |
var shippingCharges;
|
|
|
80 |
var cartDetailsObj;
|
|
|
81 |
var jsonObjToBeStored = {};
|
|
|
82 |
var cartItems = {};
|
| 17871 |
manish.sha |
83 |
var totalSkus = 0;
|
| 17804 |
manish.sha |
84 |
var cart_details = localStorage.getItem('cart_details');
|
|
|
85 |
if(cart_details!=undefined){
|
|
|
86 |
cartDetailsObj = JSON.parse(cart_details);
|
|
|
87 |
totalCartQuantity = cartDetailsObj.totalCartQuantity;
|
|
|
88 |
totalCartValue = cartDetailsObj.totalCartValue;
|
|
|
89 |
cartItems = cartDetailsObj.cartItems;
|
|
|
90 |
}
|
|
|
91 |
var inc = 0;
|
|
|
92 |
var dec = 0;
|
|
|
93 |
var sku = btn.data('id');
|
|
|
94 |
var unitPrice = btn.data('price');
|
|
|
95 |
var prodname = $(".number-spinner").data('name');
|
|
|
96 |
var brandname = $(".number-spinner").data('brand');
|
|
|
97 |
if (btn.attr('data-dir') == 'up') {
|
|
|
98 |
if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {
|
|
|
99 |
if(parseInt(input.val())<5){
|
|
|
100 |
inc = 1;
|
|
|
101 |
newVal = parseInt(oldValue) + inc;
|
|
|
102 |
}else{
|
|
|
103 |
inc = 5-(parseInt(input.val())%5);
|
|
|
104 |
newVal = parseInt(oldValue) + inc;
|
|
|
105 |
if(newVal>parseInt(input.attr('max'))){
|
|
|
106 |
inc = parseInt(input.attr('max')) - parseInt(oldValue);
|
|
|
107 |
newVal = parseInt(oldValue) + inc;
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}else{
|
|
|
111 |
newVal = parseInt(oldValue);
|
|
|
112 |
btn.prop("disabled", true);
|
|
|
113 |
}
|
| 17905 |
manish.sha |
114 |
if(newVal==parseInt(input.attr('max'))){
|
|
|
115 |
input.attr('style', 'border: 2px solid #ff0000');
|
|
|
116 |
}else{
|
|
|
117 |
input.attr('style', 'border: 1px solid #CCCCCC');
|
|
|
118 |
}
|
| 17804 |
manish.sha |
119 |
totalCartQuantity = totalCartQuantity + inc;
|
|
|
120 |
} else {
|
|
|
121 |
if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {
|
|
|
122 |
dec = 1;
|
|
|
123 |
newVal = parseInt(oldValue) - dec;
|
|
|
124 |
}else{
|
|
|
125 |
btn.prop("disabled", true);
|
|
|
126 |
}
|
| 17905 |
manish.sha |
127 |
if(newVal==parseInt(input.attr('min'))){
|
|
|
128 |
input.attr('style', 'border: 2px solid #5bc0de');
|
|
|
129 |
}else{
|
|
|
130 |
input.attr('style', 'border: 1px solid #CCCCCC');
|
|
|
131 |
}
|
| 17804 |
manish.sha |
132 |
totalCartQuantity = totalCartQuantity - dec;
|
|
|
133 |
}
|
| 17905 |
manish.sha |
134 |
$("span.lineitemqty[data-id='"+sku+"']").text(newVal);
|
| 17804 |
manish.sha |
135 |
btn.closest('.number-spinner').find('input').val(newVal);
|
|
|
136 |
if(cartDetailsObj==undefined){
|
|
|
137 |
jsonObjToBeStored['totalCartQuantity'] = totalCartQuantity;
|
|
|
138 |
totalCartValue = totalCartValue + (unitPrice * newVal);
|
|
|
139 |
jsonObjToBeStored['totalCartValue'] = totalCartValue;
|
|
|
140 |
var itemDetail = {};
|
|
|
141 |
itemDetail['quantity']=newVal;
|
|
|
142 |
itemDetail['unitprice']=unitPrice;
|
|
|
143 |
itemDetail['productname']=prodname;
|
|
|
144 |
itemDetail['brand']=brandname;
|
|
|
145 |
cartItems[sku.toString()]=itemDetail;
|
|
|
146 |
jsonObjToBeStored['cartItems']=cartItems;
|
|
|
147 |
if(parseInt(totalCartValue)>1000){
|
|
|
148 |
shippingCharges = 0;
|
|
|
149 |
}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<500){
|
|
|
150 |
shippingCharges = 50;
|
|
|
151 |
}else{
|
|
|
152 |
shippingCharges = 100;
|
|
|
153 |
}
|
| 17871 |
manish.sha |
154 |
$.each( cartItems, function(itemId,value){
|
|
|
155 |
if(value['quantity']>0){
|
|
|
156 |
totalSkus = totalSkus +1;
|
|
|
157 |
}
|
|
|
158 |
});
|
|
|
159 |
jsonObjToBeStored['totalSkus']=totalSkus;
|
| 17832 |
manish.sha |
160 |
jsonObjToBeStored['shippingCharges'] = shippingCharges;
|
| 17804 |
manish.sha |
161 |
localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));
|
|
|
162 |
}else{
|
|
|
163 |
cartDetailsObj.totalCartQuantity = totalCartQuantity;
|
|
|
164 |
var itemDetail = cartItems[sku.toString()];
|
|
|
165 |
if(itemDetail==undefined){
|
|
|
166 |
var itemDetail = {};
|
|
|
167 |
itemDetail['quantity']=newVal;
|
|
|
168 |
itemDetail['unitprice']=unitPrice;
|
|
|
169 |
itemDetail['productname']=prodname;
|
|
|
170 |
itemDetail['brand']=brandname;
|
|
|
171 |
totalCartValue = totalCartValue + (unitPrice * newVal);
|
|
|
172 |
cartItems[sku.toString()]=itemDetail;
|
|
|
173 |
}else{
|
|
|
174 |
totalCartValue = totalCartValue - (cartItems[sku.toString()].quantity * cartItems[sku.toString()].unitprice) + (unitPrice * newVal);
|
|
|
175 |
if(newVal==0){
|
| 17832 |
manish.sha |
176 |
cartItems[sku.toString()].quantity = 0;
|
|
|
177 |
cartItems[sku.toString()].unitprice = unitPrice;
|
| 17804 |
manish.sha |
178 |
}else{
|
|
|
179 |
cartItems[sku.toString()].quantity = newVal;
|
|
|
180 |
cartItems[sku.toString()].unitprice = unitPrice;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
}
|
| 17871 |
manish.sha |
184 |
$.each( cartItems, function(itemId,value){
|
|
|
185 |
if(value['quantity']>0){
|
|
|
186 |
totalSkus = totalSkus +1;
|
|
|
187 |
}
|
|
|
188 |
});
|
| 17804 |
manish.sha |
189 |
cartDetailsObj.totalCartValue = totalCartValue;
|
|
|
190 |
cartDetailsObj.cartItems = cartItems;
|
| 17871 |
manish.sha |
191 |
cartDetailsObj.totalSkus = totalSkus;
|
| 17804 |
manish.sha |
192 |
if(parseInt(totalCartValue)>1000){
|
|
|
193 |
shippingCharges = 0;
|
| 17905 |
manish.sha |
194 |
}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<1000){
|
| 17804 |
manish.sha |
195 |
shippingCharges = 50;
|
| 17905 |
manish.sha |
196 |
}else if(parseInt(totalCartValue)>0 && parseInt(totalCartValue)<500){
|
|
|
197 |
shippingCharges = 100;
|
| 17804 |
manish.sha |
198 |
}else{
|
| 17905 |
manish.sha |
199 |
shippingCharges = 0;
|
| 17804 |
manish.sha |
200 |
}
|
|
|
201 |
cartDetailsObj.shippingCharges = shippingCharges;
|
|
|
202 |
localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
|
|
|
203 |
}
|
| 17832 |
manish.sha |
204 |
$('div.cartitemstotal span.itemstotal').text('₹ '+numberWithCommas(totalCartValue));
|
|
|
205 |
$('div.cartitemstotal span.shippingval').text('₹ '+numberWithCommas(shippingCharges));
|
| 17828 |
manish.sha |
206 |
var payable = 0;
|
| 17804 |
manish.sha |
207 |
if(shippingCharges>0){
|
| 17828 |
manish.sha |
208 |
if(totalCartValue>0){
|
|
|
209 |
$('.cartitemstotal').removeClass('hidden');
|
|
|
210 |
payable = parseInt(shippingCharges)+parseInt(totalCartValue);
|
| 17832 |
manish.sha |
211 |
}else{
|
|
|
212 |
payable = 0;
|
| 17828 |
manish.sha |
213 |
}
|
| 17820 |
manish.sha |
214 |
}else{
|
| 17828 |
manish.sha |
215 |
payable = parseInt(totalCartValue);
|
|
|
216 |
$('.cartitemstotal').addClass('hidden');
|
| 17804 |
manish.sha |
217 |
}
|
| 17832 |
manish.sha |
218 |
$('div.cartgrandtotal span.pull-right').text('₹ '+numberWithCommas(payable));
|
|
|
219 |
|
|
|
220 |
if(payable>0){
|
|
|
221 |
$('button.checkoutbtn').prop( "disabled", false );
|
|
|
222 |
}else{
|
|
|
223 |
$('button.checkoutbtn').prop( "disabled", true );
|
|
|
224 |
}
|
| 17905 |
manish.sha |
225 |
if(!$('div.cartitemstotal').hasClass('hidden')){
|
|
|
226 |
$('div.scroll').attr('style', 'margin-bottom: 155px');
|
|
|
227 |
}else{
|
|
|
228 |
$('div.scroll').attr('style', 'margin-bottom: 100px');
|
|
|
229 |
}
|
| 17804 |
manish.sha |
230 |
});
|
|
|
231 |
|
|
|
232 |
function numberWithCommas(x) {
|
|
|
233 |
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
$(document).on('click','.changepincode',function(){
|
| 17881 |
manish.sha |
237 |
var pincode = "pin_"+$('.pincodeval').val();
|
| 17804 |
manish.sha |
238 |
var url = apihost + 'cartdetails/?user_id='+me;
|
|
|
239 |
var newForm = $('<form>', {
|
|
|
240 |
'action': url,
|
|
|
241 |
'method':'post'
|
|
|
242 |
}).append($('<input>', {
|
|
|
243 |
'name': 'cart_details',
|
|
|
244 |
'value': localStorage.getItem('cart_details'),
|
|
|
245 |
'type': 'hidden'
|
|
|
246 |
})).append($('<input>', {
|
|
|
247 |
'name': 'pincode',
|
|
|
248 |
'value': pincode,
|
|
|
249 |
'type': 'hidden'
|
|
|
250 |
}));
|
|
|
251 |
newForm.submit();
|
|
|
252 |
});
|
|
|
253 |
|
|
|
254 |
$(document).on('click','.checkoutbtn',function(){
|
|
|
255 |
var url = apihost + 'shippings/';
|
|
|
256 |
var newForm = $('<form>', {
|
|
|
257 |
'action': url,
|
|
|
258 |
'method':'post'
|
|
|
259 |
}).append($('<input>', {
|
|
|
260 |
'name': 'cart_details',
|
|
|
261 |
'value': localStorage.getItem('cart_details'),
|
|
|
262 |
'type': 'hidden'
|
|
|
263 |
}));
|
|
|
264 |
newForm.submit();
|
| 17822 |
manish.sha |
265 |
});
|
|
|
266 |
$(document).on('click','.backtodeals',function(){
|
|
|
267 |
history.back();
|
| 17804 |
manish.sha |
268 |
});
|