| 17804 |
manish.sha |
1 |
function loadCartDetails(){
|
| 17766 |
manish.sha |
2 |
$('.itemquantity').attr('disabled', 'true');
|
|
|
3 |
var cart_details = localStorage.getItem('cart_details');
|
|
|
4 |
if(cart_details==undefined){
|
|
|
5 |
$(".pmfooter span.carttotalval").text('0');
|
|
|
6 |
$(".pmfooter span.badge").text('0');
|
|
|
7 |
$(".pmfooter").addClass('hidden');
|
|
|
8 |
}else{
|
|
|
9 |
var cartDetailsObj = JSON.parse(cart_details);
|
|
|
10 |
if(cartDetailsObj.totalCartQuantity > 0){
|
|
|
11 |
$(".pmfooter span.badge").text(cartDetailsObj.totalCartQuantity.toString());
|
|
|
12 |
var totalCartValue = cartDetailsObj.totalCartValue;
|
|
|
13 |
var priceChangeMap = {};
|
|
|
14 |
$.each(cartDetailsObj.cartItems, function(key,val) {
|
|
|
15 |
var newUnitPrice = $(".number-spinner button[data-id='"+key+"']").data('price');
|
| 17774 |
manish.sha |
16 |
if(newUnitPrice!=undefined){
|
|
|
17 |
$(".number-spinner button[data-id='"+key+"']").closest('.number-spinner').find('input').val(val.quantity);
|
|
|
18 |
if(parseInt(newUnitPrice)!=parseInt(val.unitprice)){
|
|
|
19 |
totalCartValue = totalCartValue - (parseInt(val.unitprice)*parseInt(val.quantity)) + (parseInt(newUnitPrice)*parseInt(val.quantity));
|
|
|
20 |
priceChangeMap[key] = newUnitPrice;
|
|
|
21 |
}
|
| 17766 |
manish.sha |
22 |
}
|
|
|
23 |
});
|
|
|
24 |
$(".pmfooter span.carttotalval").text(numberWithCommas(totalCartValue));
|
| 17774 |
manish.sha |
25 |
if(totalCartValue!=undefined){
|
|
|
26 |
cartDetailsObj.totalCartValue = totalCartValue;
|
|
|
27 |
}
|
| 17766 |
manish.sha |
28 |
var cartItems = cartDetailsObj.cartItems;
|
|
|
29 |
$.each(priceChangeMap, function(key,val) {
|
| 17804 |
manish.sha |
30 |
cartItems[key].unitprice = val;
|
| 17766 |
manish.sha |
31 |
});
|
|
|
32 |
cartDetailsObj.cartItems = cartItems;
|
|
|
33 |
localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
|
|
|
34 |
$(".pmfooter").removeClass('hidden');
|
|
|
35 |
}else{
|
| 17827 |
manish.sha |
36 |
$.each(cartDetailsObj.cartItems, function(key,val) {
|
|
|
37 |
var newUnitPrice = $(".number-spinner button[data-id='"+key+"']").data('price');
|
|
|
38 |
if(newUnitPrice!=undefined){
|
|
|
39 |
$(".number-spinner button[data-id='"+key+"']").closest('.number-spinner').find('input').val(val.quantity);
|
|
|
40 |
if(parseInt(newUnitPrice)!=parseInt(val.unitprice)){
|
|
|
41 |
totalCartValue = totalCartValue - (parseInt(val.unitprice)*parseInt(val.quantity)) + (parseInt(newUnitPrice)*parseInt(val.quantity));
|
|
|
42 |
priceChangeMap[key] = newUnitPrice;
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
});
|
| 17766 |
manish.sha |
46 |
$(".pmfooter span.carttotalval").text('0');
|
|
|
47 |
$(".pmfooter span.badge").text('0');
|
|
|
48 |
$(".pmfooter").addClass('hidden');
|
|
|
49 |
}
|
| 17804 |
manish.sha |
50 |
}
|
| 17766 |
manish.sha |
51 |
}
|
| 17804 |
manish.sha |
52 |
$(function(){
|
|
|
53 |
loadCartDetails();
|
|
|
54 |
});
|
|
|
55 |
$(document).on('click','.number-spinner button',function(){
|
| 17766 |
manish.sha |
56 |
btn = $(this);
|
|
|
57 |
input = btn.closest('.number-spinner').find('input');
|
|
|
58 |
oldValue = btn.closest('.number-spinner').find('input').val().trim(),
|
|
|
59 |
newVal = 0;
|
|
|
60 |
btn.closest('.number-spinner').find('button').prop("disabled", false);
|
|
|
61 |
var totalCartQuantity = 0;
|
|
|
62 |
var totalCartValue = 0;
|
|
|
63 |
var cartDetailsObj;
|
|
|
64 |
var jsonObjToBeStored = {};
|
|
|
65 |
var cartItems = {};
|
|
|
66 |
var cart_details = localStorage.getItem('cart_details');
|
|
|
67 |
if(cart_details!=undefined){
|
|
|
68 |
cartDetailsObj = JSON.parse(cart_details);
|
|
|
69 |
totalCartQuantity = cartDetailsObj.totalCartQuantity;
|
|
|
70 |
totalCartValue = cartDetailsObj.totalCartValue;
|
|
|
71 |
cartItems = cartDetailsObj.cartItems;
|
|
|
72 |
}
|
|
|
73 |
var inc = 0;
|
|
|
74 |
var dec = 0;
|
|
|
75 |
var sku = btn.data('id');
|
|
|
76 |
var unitPrice = btn.data('price');
|
|
|
77 |
var prodname = $(".number-spinner").data('name');
|
|
|
78 |
var brandname = $(".number-spinner").data('brand');
|
|
|
79 |
if (btn.attr('data-dir') == 'up') {
|
|
|
80 |
if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {
|
|
|
81 |
if(parseInt(input.val())<5){
|
|
|
82 |
inc = 1;
|
|
|
83 |
newVal = parseInt(oldValue) + inc;
|
|
|
84 |
}else{
|
|
|
85 |
inc = 5-(parseInt(input.val())%5);
|
|
|
86 |
newVal = parseInt(oldValue) + inc;
|
| 17804 |
manish.sha |
87 |
if(newVal>parseInt(input.attr('max'))){
|
|
|
88 |
inc = parseInt(input.attr('max')) - parseInt(oldValue);
|
|
|
89 |
newVal = parseInt(oldValue) + inc;
|
|
|
90 |
}
|
| 17766 |
manish.sha |
91 |
}
|
|
|
92 |
}else{
|
|
|
93 |
newVal = parseInt(oldValue);
|
|
|
94 |
btn.prop("disabled", true);
|
|
|
95 |
}
|
|
|
96 |
totalCartQuantity = totalCartQuantity + inc;
|
|
|
97 |
} else {
|
|
|
98 |
if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {
|
|
|
99 |
dec = 1;
|
|
|
100 |
newVal = parseInt(oldValue) - dec;
|
|
|
101 |
}else{
|
|
|
102 |
btn.prop("disabled", true);
|
|
|
103 |
}
|
|
|
104 |
totalCartQuantity = totalCartQuantity - dec;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
btn.closest('.number-spinner').find('input').val(newVal);
|
|
|
108 |
if(cartDetailsObj==undefined){
|
|
|
109 |
jsonObjToBeStored['totalCartQuantity'] = totalCartQuantity;
|
|
|
110 |
totalCartValue = totalCartValue + (unitPrice * newVal);
|
|
|
111 |
jsonObjToBeStored['totalCartValue'] = totalCartValue;
|
|
|
112 |
var itemDetail = {};
|
|
|
113 |
itemDetail['quantity']=newVal;
|
|
|
114 |
itemDetail['unitprice']=unitPrice;
|
|
|
115 |
itemDetail['productname']=prodname;
|
|
|
116 |
itemDetail['brand']=brandname;
|
|
|
117 |
cartItems[sku.toString()]=itemDetail;
|
|
|
118 |
jsonObjToBeStored['cartItems']=cartItems;
|
|
|
119 |
localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));
|
|
|
120 |
}else{
|
|
|
121 |
cartDetailsObj.totalCartQuantity = totalCartQuantity;
|
|
|
122 |
var itemDetail = cartItems[sku.toString()];
|
|
|
123 |
if(itemDetail==undefined){
|
|
|
124 |
var itemDetail = {};
|
|
|
125 |
itemDetail['quantity']=newVal;
|
|
|
126 |
itemDetail['unitprice']=unitPrice;
|
|
|
127 |
itemDetail['productname']=prodname;
|
|
|
128 |
itemDetail['brand']=brandname;
|
|
|
129 |
totalCartValue = totalCartValue + (unitPrice * newVal);
|
|
|
130 |
cartItems[sku.toString()]=itemDetail;
|
|
|
131 |
}else{
|
|
|
132 |
totalCartValue = totalCartValue - (cartItems[sku.toString()].quantity * cartItems[sku.toString()].unitprice) + (unitPrice * newVal);
|
|
|
133 |
if(newVal==0){
|
| 17831 |
manish.sha |
134 |
cartItems[sku.toString()].quantity = 0;
|
|
|
135 |
cartItems[sku.toString()].unitprice = unitPrice;
|
| 17766 |
manish.sha |
136 |
}else{
|
|
|
137 |
cartItems[sku.toString()].quantity = newVal;
|
|
|
138 |
cartItems[sku.toString()].unitprice = unitPrice;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
}
|
|
|
142 |
cartDetailsObj.totalCartValue = totalCartValue;
|
|
|
143 |
cartDetailsObj.cartItems = cartItems;
|
|
|
144 |
localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
|
|
|
145 |
}
|
|
|
146 |
if(totalCartQuantity > 0){
|
|
|
147 |
$(".pmfooter span.carttotalval").text(numberWithCommas(totalCartValue));
|
|
|
148 |
$(".pmfooter span.badge").text(totalCartQuantity);
|
|
|
149 |
$(".pmfooter").removeClass('hidden');
|
|
|
150 |
}else{
|
|
|
151 |
$(".pmfooter span.carttotalval").text('0');
|
|
|
152 |
$(".pmfooter span.badge").text('0');
|
|
|
153 |
$(".pmfooter").addClass('hidden');
|
|
|
154 |
}
|
|
|
155 |
});
|
|
|
156 |
|
|
|
157 |
$(document).on('click','.see_more_colors',function(){
|
| 17804 |
manish.sha |
158 |
var id = $(".number-spinner button").data('id');
|
|
|
159 |
$(".morecoloroptions_"+$(this).data('id')+" button:first-child" ).addClass("active");
|
| 17766 |
manish.sha |
160 |
$('.morecoloroptions_'+$(this).data('id')).toggleClass('hidden');
|
|
|
161 |
});
|
|
|
162 |
|
| 17804 |
manish.sha |
163 |
$(document).on('click','.button-checkbox > .btn',function(){
|
|
|
164 |
$(this).addClass('active').siblings().removeClass('active');
|
|
|
165 |
var cart_details = localStorage.getItem('cart_details');
|
|
|
166 |
if(cart_details!=undefined){
|
|
|
167 |
var cartDetailsObj = JSON.parse(cart_details);
|
|
|
168 |
var item = cartDetailsObj.cartItems[$(this).data('id')];
|
|
|
169 |
if(item!=undefined){
|
| 17819 |
manish.sha |
170 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('id',$(this).data('id'));
|
|
|
171 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('price',parseInt($(this).data('price')));
|
| 17804 |
manish.sha |
172 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").attr('max',parseInt($(this).data('max')));
|
|
|
173 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").val(item.quantity);
|
|
|
174 |
$(".viewproduct span[data-did='"+$(this).data('did')+"']").text(parseInt($(this).data('price')));
|
|
|
175 |
cartDetailsObj.cartItems[$(this).data('id')].unitprice = parseInt($(this).data('price'));
|
|
|
176 |
localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
|
|
|
177 |
}else{
|
| 17819 |
manish.sha |
178 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('id',$(this).data('id'));
|
|
|
179 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('price',parseInt($(this).data('price')));
|
| 17804 |
manish.sha |
180 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").attr('max',parseInt($(this).data('max')));
|
|
|
181 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").val('0');
|
|
|
182 |
$(".viewproduct span[data-did='"+$(this).data('did')+"']").text(parseInt($(this).data('price')));
|
|
|
183 |
}
|
|
|
184 |
}else{
|
| 17819 |
manish.sha |
185 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('id',$(this).data('id'));
|
|
|
186 |
$(".number-spinner button[data-did='"+$(this).data('did')+"']").data('price',parseInt($(this).data('price')));
|
| 17804 |
manish.sha |
187 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").attr('max',parseInt($(this).data('max')));
|
|
|
188 |
$(".number-spinner input[data-did='"+$(this).data('did')+"']").val('0');
|
|
|
189 |
$(".viewproduct span[data-did='"+$(this).data('did')+"']").text(parseInt($(this).data('price')));
|
|
|
190 |
}
|
|
|
191 |
|
| 17766 |
manish.sha |
192 |
});
|
|
|
193 |
|
|
|
194 |
$("#bottomNav").click(function(){
|
| 17775 |
manish.sha |
195 |
var url = apihost + 'cartdetails/?user_id='+me;
|
| 17766 |
manish.sha |
196 |
var newForm = $('<form>', {
|
|
|
197 |
'action': url,
|
|
|
198 |
'method':'post'
|
|
|
199 |
}).append($('<input>', {
|
|
|
200 |
'name': 'cart_details',
|
|
|
201 |
'value': localStorage.getItem('cart_details'),
|
|
|
202 |
'type': 'hidden'
|
|
|
203 |
}));
|
|
|
204 |
newForm.submit();
|
|
|
205 |
});
|
|
|
206 |
|
|
|
207 |
function numberWithCommas(x) {
|
|
|
208 |
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
|
209 |
}
|
| 17839 |
manish.sha |
210 |
|
|
|
211 |
$(document).on('click','.radGroup2',function(){
|
|
|
212 |
var pin = $(this).data('pin');
|
|
|
213 |
var add_id = $(this).data('id');
|
|
|
214 |
$('#loadingModal').modal('show');
|
|
|
215 |
$.ajax({
|
|
|
216 |
method: "GET",
|
|
|
217 |
url: apihost+"shippings/isServicable/"+pin,
|
|
|
218 |
})
|
|
|
219 |
.done(function( msg ) {
|
|
|
220 |
$('#loadingModal').modal('hide');
|
|
|
221 |
if(msg== 'true'){
|
|
|
222 |
$('.myaddress').removeClass('addressselect');
|
|
|
223 |
$('#address'+add_id).addClass('addressselect');
|
|
|
224 |
// $('#message_success').empty();
|
|
|
225 |
// $('#message_success').append();
|
|
|
226 |
// $('#message_success').removeClass('hidden');
|
|
|
227 |
|
|
|
228 |
// setTimeout(function() {
|
|
|
229 |
// $('#message_success ').addClass('hidden');
|
|
|
230 |
// }, 2000);
|
|
|
231 |
}
|
|
|
232 |
if(msg== 'false'){
|
|
|
233 |
$('#message').empty();
|
|
|
234 |
$('#message').append("Location is not serviceable...");
|
|
|
235 |
$('#message').removeClass('hidden');
|
|
|
236 |
$("input:radio").removeAttr("checked");
|
|
|
237 |
$('.myaddress').removeClass('addressselect');
|
|
|
238 |
setTimeout(function() {
|
|
|
239 |
$('#message').addClass('hidden');
|
|
|
240 |
}, 2000);
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
// alert(msg);
|
|
|
244 |
});
|
|
|
245 |
});
|
|
|
246 |
|
|
|
247 |
$(document).on('click','#showmore',function(){
|
|
|
248 |
$("#showmoreaddressdropdown").toggle();
|
|
|
249 |
if($('#showmore').html() == 'Show More')
|
|
|
250 |
{
|
|
|
251 |
$("#showmore").html('Show Less');
|
|
|
252 |
}
|
|
|
253 |
else if($("#showmore").html() == 'Show Less')
|
|
|
254 |
{
|
|
|
255 |
// $("#showmore").empty();
|
|
|
256 |
$("#showmore").html('Show More');
|
|
|
257 |
}
|
|
|
258 |
});
|
|
|
259 |
|
| 17766 |
manish.sha |
260 |
/*
|
|
|
261 |
$('.button-checkbox').each(function () {
|
|
|
262 |
|
|
|
263 |
// Settings
|
|
|
264 |
var $widget = $(this),
|
|
|
265 |
$button = $widget.find('button'),
|
|
|
266 |
$checkbox = $widget.find('input:checkbox'),
|
|
|
267 |
color = $button.data('color'),
|
|
|
268 |
settings = {
|
|
|
269 |
on: {
|
|
|
270 |
icon: 'glyphicon glyphicon-check'
|
|
|
271 |
},
|
|
|
272 |
off: {
|
|
|
273 |
icon: 'glyphicon glyphicon-unchecked'
|
|
|
274 |
}
|
|
|
275 |
};
|
|
|
276 |
|
|
|
277 |
// Event Handlers
|
|
|
278 |
$button.on('click', function () {
|
|
|
279 |
$checkbox.prop('checked', !$checkbox.is(':checked'));
|
|
|
280 |
$checkbox.triggerHandler('change');
|
|
|
281 |
updateDisplay();
|
|
|
282 |
});
|
|
|
283 |
$checkbox.on('change', function () {
|
|
|
284 |
updateDisplay();
|
|
|
285 |
});
|
|
|
286 |
|
|
|
287 |
// Actions
|
|
|
288 |
function updateDisplay() {
|
|
|
289 |
var isChecked = $checkbox.is(':checked');
|
|
|
290 |
|
|
|
291 |
// Set the button's state
|
|
|
292 |
$button.data('state', (isChecked) ? "on" : "off");
|
|
|
293 |
|
|
|
294 |
// Set the button's icon
|
|
|
295 |
$button.find('.state-icon')
|
|
|
296 |
.removeClass()
|
|
|
297 |
.addClass('state-icon ' + settings[$button.data('state')].icon);
|
|
|
298 |
|
|
|
299 |
// Update the button's color
|
|
|
300 |
if (isChecked) {
|
|
|
301 |
$button
|
|
|
302 |
.removeClass('btn-default')
|
|
|
303 |
.addClass('colorbtn active');
|
|
|
304 |
}
|
|
|
305 |
else {
|
|
|
306 |
$button
|
|
|
307 |
.removeClass('colorbtn active')
|
|
|
308 |
.addClass('btn-default');
|
|
|
309 |
}
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
// Initialization
|
|
|
313 |
function init() {
|
|
|
314 |
|
|
|
315 |
updateDisplay();
|
|
|
316 |
|
|
|
317 |
// Inject the icon if applicable
|
|
|
318 |
if ($button.find('.state-icon').length == 0) {
|
|
|
319 |
$button.prepend('<i class="state-icon ' + settings[$button.data('state')].icon + '"></i>');
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
init();
|
|
|
323 |
});*/
|