
PK 
//###########################Init Custom Function#####################
var InitShoping = (function(){
// here is private method and properties
var cart = [];
var cartmy =[];
function Item(cpid, blockname, plotno, plotsize, baseprice, plccorner, plcpark, plcroad, edc, camcharge, discountrate, discountamt, saleprice, count, image, locationid) {
this.cpid = cpid;
this.blockname = blockname;
this.plotno = plotno;
this.plotsize = plotsize;
this.baseprice = baseprice;
this.plccorner = plccorner;
this.plcpark = plcpark;
this.plcroad = plcroad;
this.edc = edc;
this.camcharge = camcharge;
this.discountrate = discountrate;
this.discountamt = discountamt;
this.saleprice = saleprice;
this.count = count;
this.image = image;
this.locationid = locationid;
};
function saveCart(){
//localStorage.setItem("shopconfrmCart",JSON.stringify(cart));
$.session.set("shopconfrmCart",JSON.stringify(cart));
//$.session.set("shopingCart",JSON.stringify(cart));
};
function loadCart(){
//cart = (JSON.parse(localStorage.getItem('shopconfrmCart'))!=null)?JSON.parse(localStorage.getItem('shopconfrmCart')):[];
cart = (JSON.parse(sessionStorage.getItem('shopconfrmCart'))!==null)?JSON.parse(sessionStorage.getItem('shopconfrmCart')):[];
/*var app_list = localStorage.getItem('shopconfrmCart');
var cart = (app_list != null)?JSON.parse(app_list) : [];*/
// var keyval = $.session.get("shopingCart");
};
function saveClearCart(msg,orderid){
//localStorage.setItem("shopconfrmCart",JSON.stringify(cart));
$.session.set("shopconfrmCart",JSON.stringify(cart));
window.location.href = 'thankyou.php?shopping='+msg+","+orderid;
};
loadCart();
//here is public method and properties
var obj = {};
obj.addCItemToCart = function(cpid, blockname, plotno, plotsize, baseprice, plccorner, plcpark, plcroad, edc, camcharge, discountrate, discountamt, saleprice, count, image, locationid) {
for (var i in cart) {
if (cart[i].cpid === cpid) {
cart[i].count +=count;
saveCart();
return;
}
}
var item = new Item(cpid, blockname, plotno, plotsize, baseprice, plccorner, plcpark, plcroad, edc, camcharge, discountrate, discountamt, saleprice, count, image, locationid);
cart.push(item);
saveCart();
};
obj.setCountForItem = function(cpid,count) {
for (var i in cart) {
if (cart[i].cpid === cpid) {
cart[i].count =count;
break;
}
}
saveCart();
};
obj.removeCItemFromCart = function(cpid) {
for (var i in cart) {
if (cart[i].cpid === cpid) {
/*cart[i].count--;
if (cart[i].count === 0) {*/
cart.splice(i, 1);
/*}
break;*/
}
}
saveCart();
};
obj.removeItemFromCartAll = function(cpid) {
for (var i in cart) {
if (cart[i].cpid === cpid) {
cart.splice(i, 1);
break;
}
}
saveCart();
};
obj.clearCart = function() {
cart = [];
saveCart();
};
obj.clearSaveCart = function(msg,orderid) {
cart = [];
saveClearCart(msg,orderid);
};
obj.cartlItem = function() {
var lcount = cart.length;
return (lcount !==0) ? lcount : 0;
};
obj.countCart = function() {
var totalCount = 0;
for (var i in cart) {
totalCount += cart[i].count;
}
return totalCount;
};
obj.totalCart = function() {
var totalcost = 0;
for (var i in cart) {
totalcost += cart[i].baseprice*cart[i].count;
}
return totalcost.toFixed(2);
};
obj.listCart = function() {
var cartCopy = [];
for (var i in cart) {
var item = cart[i];
var itemCopy = {};
for (var p in item) {
itemCopy[p] = item[p];
}
itemCopy.total=(item.baseprice*item.count).toFixed(2);
cartCopy.push(itemCopy);
}
return cartCopy;
};
/* obj.listVariantCart= function(cpid) {
for (var i in cart) {
if (cart[i].cpid === cpid) {
qty = cart[i].count;
isfound=true;
break;
}
}
if(isfound===true){
console.log('count: ','cpid: ',cpid,' & qty: ',qty);
//$("#xp_"+cpid).html(qty);
}else{
// $("#xp_"+cpid+" .items-count").html('0');
console.log('remove: ','cpid: ',cpid,' & qty: ',qty);
}
}; */
return obj;
})();


PK 99