Rev 17919 | Rev 17953 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
function loadCartPageDetails(){var payable = $('div.cartgrandtotal span.pull-right').text().split(" ");payable = payable[2];if(parseInt(payable)>0){$('button.checkoutbtn').prop( "disabled", false );}else{$('button.checkoutbtn').prop( "disabled", true );}var input = $('input#refresh').val();if(input == 'yes'){var cart_details = localStorage.getItem('cart_details');if(cart_details!=undefined){var cartDetailsObj = JSON.parse(cart_details);var totalCartValue = cartDetailsObj.totalCartValuevar totalCartQuantity = cartDetailsObj.totalCartQuantityvar cartItems = cartDetailsObj.cartItemsvar shippingCharges =cartDetailsObj.shippingCharges;var totalSkus = cartDetailsObj.totalSkus;$.each(cartDetailsObj.cartItems, function(key,val) {$("div.number-spinner button[data-id='"+key+"']").closest('.number-spinner').find('input').val(val.quantity);$("span.lineitemqty[data-id='"+key+"']").text(val.quantity);$("span.lineitemtotal[data-id='"+key+"']").text(' ₹ '+ (parseInt(val.quantity)*parseInt(val.unitprice)).toString());});$('div.cartitemstotal span.itemstotal').text('₹ '+numberWithCommas(totalCartValue));$('div.cartitemstotal span.shippingval').text('₹ '+numberWithCommas(shippingCharges));var payable = 0;if(shippingCharges>0){if(totalCartValue>0){$('.cartitemstotal').removeClass('hidden');payable = parseInt(shippingCharges)+parseInt(totalCartValue);}else{payable = 0;}}else{payable = parseInt(totalCartValue);$('.cartitemstotal').addClass('hidden');}$('div.cartgrandtotal span.pull-right').text('₹ '+numberWithCommas(payable));if(payable>0){$('button.checkoutbtn').prop( "disabled", false );}else{$('button.checkoutbtn').prop( "disabled", true );}if(!$('div.cartitemstotal').hasClass('hidden')){$('div.scroll').attr('style', 'margin-bottom: 155px');}else{$('div.scroll').attr('style', 'margin-bottom: 100px');}var estimateString = $('div.popover-markup').data('str');if(estimateString!="Can't ship here"){$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {$(this).prop('disabled', false);});}else{$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {$(this).prop('disabled', true);});}}}else{$('input#refresh').val('yes');var estimateString = $('div.popover-markup').data('str');if(estimateString!="Can't ship here"){$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {$(this).prop('disabled', false);});var cart_details = localStorage.getItem('cart_details');localStorage.removeItem('cart_details');if(cart_details!=undefined){var totalCartValue = 0;var totalCartQuantity = 0;var cartItems = {};var jsonObjToBeStored = {};var shippingCharges = 0;var totalSkus = 0;totalCartValue = $('.cartitemstotal').data('itemtotal');shippingCharges = $('.cartitemstotal').data('shipping');$('.number-spinner').each(function (index, val) {var element = $(val);var quantity = element.find("input").val();if(parseInt(quantity)>0){var sku = element.find("button[data-dir='up']").data('id');var price = element.find("button[data-dir='up']").data('price');var prodname = $(this).data('name');var brandname = $(this).data('brand');var itemDetail = {};totalCartQuantity = totalCartQuantity + parseInt(quantity);totalSkus = totalSkus +1;itemDetail['quantity']=parseInt(quantity);itemDetail['unitprice']=parseInt(price);itemDetail['productname']=prodname;itemDetail['brand']=brandname;cartItems[sku.toString()]=itemDetail;}});jsonObjToBeStored['totalCartQuantity'] = totalCartQuantity;jsonObjToBeStored['totalCartValue'] = totalCartValue;jsonObjToBeStored['cartItems'] = cartItems;jsonObjToBeStored['shippingCharges'] = shippingCharges;jsonObjToBeStored['totalSkus'] = totalSkus;localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));}}else{var cart_details = localStorage.getItem('cart_details');if(cart_details!=undefined){var cartDetailsObj = JSON.parse(cart_details);var totalCartValue = cartDetailsObj.totalCartValuevar totalCartQuantity = cartDetailsObj.totalCartQuantityvar cartItems = cartDetailsObj.cartItemsvar jsonObjToBeStored = {};var shippingCharges = $('.cartitemstotal').data('shipping');var totalSkus = cartDetailsObj.totalSkus$('.number-spinner').each(function (index, val) {var element = $(val);var quantity = element.find("input").val();var estimate = element.data('estimate');if(parseInt(quantity)==0 && estimate==""){var sku = element.find("button[data-dir='up']").data('id');var price = element.find("button[data-dir='up']").data('price');var prodname = $(this).data('name');var brandname = $(this).data('brand');var itemDetail = cartDetailsObj.cartItems[sku.toString()];if(itemDetail==undefined){itemDetail = {};itemDetail['quantity']=parseInt(quantity);itemDetail['unitprice']=parseInt(price);itemDetail['productname']=prodname;itemDetail['brand']=brandname;cartItems[sku.toString()] = itemDetail;}else{totalCartValue = totalCartValue - (itemDetail.quantity*itemDetail.unitprice);totalSkus = totalSkus -1;totalCartQuantity = totalCartQuantity - itemDetail.quantity;itemDetail.quantity = 0;itemDetail.unitprice = parseInt(price);cartItems[sku.toString()] = itemDetail;}}});if(parseInt(totalCartValue)>1000){shippingCharges = 0;}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<1000){shippingCharges = 50;}else if(parseInt(totalCartValue)>0 && parseInt(totalCartValue)<500){shippingCharges = 100;}else{shippingCharges = 0;}cartDetailsObj.totalCartQuantity = totalCartQuantity;cartDetailsObj.totalCartValue = totalCartValue;cartDetailsObj.cartItems = cartItems;cartDetailsObj.shippingCharges = shippingCharges;cartDetailsObj.totalSkus = totalSkus;localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));}$('div.cartdetailscard').find('div, input, textarea, button, select').each(function () {$(this).prop('disabled', true);});}}}$(function(){loadCartPageDetails();});$(document).on('click','.number-spinner button',function(){btn = $(this);input = btn.closest('.number-spinner').find('input');oldValue = btn.closest('.number-spinner').find('input').val().trim(),newVal = 0;btn.closest('.number-spinner').find('button').prop("disabled", false);var totalCartQuantity = 0;var totalCartValue = 0;var shippingCharges;var cartDetailsObj;var jsonObjToBeStored = {};var cartItems = {};var totalSkus = 0;var cart_details = localStorage.getItem('cart_details');if(cart_details!=undefined){cartDetailsObj = JSON.parse(cart_details);totalCartQuantity = cartDetailsObj.totalCartQuantity;totalCartValue = cartDetailsObj.totalCartValue;cartItems = cartDetailsObj.cartItems;}var inc = 0;var dec = 0;var sku = btn.data('id');var unitPrice = btn.data('price');var prodname = $(".number-spinner").data('name');var brandname = $(".number-spinner").data('brand');if (btn.attr('data-dir') == 'up') {if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) {if(parseInt(input.val())<5){inc = 1;newVal = parseInt(oldValue) + inc;}else{inc = 5-(parseInt(input.val())%5);newVal = parseInt(oldValue) + inc;if(newVal>parseInt(input.attr('max'))){inc = parseInt(input.attr('max')) - parseInt(oldValue);newVal = parseInt(oldValue) + inc;}}}else{newVal = parseInt(oldValue);btn.prop("disabled", true);}if(newVal==parseInt(input.attr('max'))){input.attr('style', 'border: 2px solid #ff0000');}else{input.attr('style', 'border: 1px solid #CCCCCC');}totalCartQuantity = totalCartQuantity + inc;} else {if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) {dec = 1;newVal = parseInt(oldValue) - dec;}else{btn.prop("disabled", true);}if(newVal==parseInt(input.attr('min'))){input.attr('style', 'border: 2px solid #5bc0de');}else{input.attr('style', 'border: 1px solid #CCCCCC');}totalCartQuantity = totalCartQuantity - dec;}$("span.lineitemqty[data-id='"+sku+"']").text(newVal);btn.closest('.number-spinner').find('input').val(newVal);$("span.lineitemtotal[data-id='"+sku+"']").text(' ₹ '+ (parseInt(newVal)*parseInt(unitPrice)).toString());if(cartDetailsObj==undefined){jsonObjToBeStored['totalCartQuantity'] = totalCartQuantity;totalCartValue = totalCartValue + (unitPrice * newVal);jsonObjToBeStored['totalCartValue'] = totalCartValue;var itemDetail = {};itemDetail['quantity']=newVal;itemDetail['unitprice']=unitPrice;itemDetail['productname']=prodname;itemDetail['brand']=brandname;cartItems[sku.toString()]=itemDetail;jsonObjToBeStored['cartItems']=cartItems;if(parseInt(totalCartValue)>1000){shippingCharges = 0;}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<500){shippingCharges = 50;}else{shippingCharges = 100;}$.each( cartItems, function(itemId,value){if(value['quantity']>0){totalSkus = totalSkus +1;}});jsonObjToBeStored['totalSkus']=totalSkus;jsonObjToBeStored['shippingCharges'] = shippingCharges;localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));}else{cartDetailsObj.totalCartQuantity = totalCartQuantity;var itemDetail = cartItems[sku.toString()];if(itemDetail==undefined){var itemDetail = {};itemDetail['quantity']=newVal;itemDetail['unitprice']=unitPrice;itemDetail['productname']=prodname;itemDetail['brand']=brandname;totalCartValue = totalCartValue + (unitPrice * newVal);cartItems[sku.toString()]=itemDetail;}else{totalCartValue = totalCartValue - (cartItems[sku.toString()].quantity * cartItems[sku.toString()].unitprice) + (unitPrice * newVal);if(newVal==0){cartItems[sku.toString()].quantity = 0;cartItems[sku.toString()].unitprice = unitPrice;}else{cartItems[sku.toString()].quantity = newVal;cartItems[sku.toString()].unitprice = unitPrice;}}$.each( cartItems, function(itemId,value){if(value['quantity']>0){totalSkus = totalSkus +1;}});cartDetailsObj.totalCartValue = totalCartValue;cartDetailsObj.cartItems = cartItems;cartDetailsObj.totalSkus = totalSkus;if(parseInt(totalCartValue)>1000){shippingCharges = 0;}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<1000){shippingCharges = 50;}else if(parseInt(totalCartValue)>0 && parseInt(totalCartValue)<500){shippingCharges = 100;}else{shippingCharges = 0;}cartDetailsObj.shippingCharges = shippingCharges;localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));}$('div.cartitemstotal span.itemstotal').text('₹ '+numberWithCommas(totalCartValue));$('div.cartitemstotal span.shippingval').text('₹ '+numberWithCommas(shippingCharges));var payable = 0;if(shippingCharges>0){if(totalCartValue>0){$('.cartitemstotal').removeClass('hidden');payable = parseInt(shippingCharges)+parseInt(totalCartValue);}else{payable = 0;}}else{payable = parseInt(totalCartValue);$('.cartitemstotal').addClass('hidden');}$('div.cartgrandtotal span.pull-right').text('₹ '+numberWithCommas(payable));if(payable>0){$('button.checkoutbtn').prop( "disabled", false );}else{$('button.checkoutbtn').prop( "disabled", true );}if(!$('div.cartitemstotal').hasClass('hidden')){$('div.scroll').attr('style', 'margin-bottom: 155px');}else{$('div.scroll').attr('style', 'margin-bottom: 100px');}});function numberWithCommas(x) {return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");}$(document).on('click','.changepincode',function(){$('#cartLoadingModal').modal('show');var pincode = "pin_"+$('.pincodeval').val();var url = apihost + 'cartdetails/?user_id='+me;var newForm = $('<form>', {'action': url,'method':'post'}).append($('<input>', {'name': 'cart_details','value': localStorage.getItem('cart_details'),'type': 'hidden'})).append($('<input>', {'name': 'pincode','value': pincode,'type': 'hidden'}));newForm.submit();});$(document).on('click','.checkoutbtn',function(){$('#cartLoadingModal').modal('show');var url = apihost + 'shippings/';var newForm = $('<form>', {'action': url,'method':'post'}).append($('<input>', {'name': 'cart_details','value': localStorage.getItem('cart_details'),'type': 'hidden'}));newForm.submit();});$(document).on('click','.backtodeals',function(){$('#cartLoadingModal').modal('show');history.back();});