Subversion Repositories SmartDukaan

Rev

Rev 17830 | Rev 17833 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17830 Rev 17832
Line 1... Line 1...
1
function loadCartPageDetails(){
1
function loadCartPageDetails(){
2
	$('.itemquantity').attr('disabled', 'true');
2
	$('.itemquantity').attr('disabled', 'true');
-
 
3
	var payable = $('div.cartgrandtotal span.pull-right').text().split(" ");
-
 
4
	payable = payable[2];
-
 
5
	alert(payable);
-
 
6
	if(parseInt(payable)>0){
-
 
7
		$('button.checkoutbtn').prop( "disabled", false );
-
 
8
	}else{
-
 
9
		$('button.checkoutbtn').prop( "disabled", true );
-
 
10
	}
-
 
11
	
3
	var cart_details = localStorage.getItem('cart_details');
12
	var cart_details = localStorage.getItem('cart_details');
4
	
13
	
5
	localStorage.removeItem('cart_details');
14
	localStorage.removeItem('cart_details');
6
	var totalCartValue = 0;
15
	var totalCartValue = 0;
7
	var totalCartQuantity = 0;
16
	var totalCartQuantity = 0;
Line 112... Line 121...
112
		}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<500){
121
		}else if(parseInt(totalCartValue)>=500 && parseInt(totalCartValue)<500){
113
			shippingCharges = 50;
122
			shippingCharges = 50;
114
		}else{
123
		}else{
115
			shippingCharges = 100;
124
			shippingCharges = 100;
116
		}
125
		}
117
		jsonObjToBeStored['shippingCharges'] = totalCartValue;
126
		jsonObjToBeStored['shippingCharges'] = shippingCharges;
118
		localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));
127
		localStorage.setItem('cart_details',JSON.stringify(jsonObjToBeStored));
119
	}else{
128
	}else{
120
		cartDetailsObj.totalCartQuantity = totalCartQuantity;
129
		cartDetailsObj.totalCartQuantity = totalCartQuantity;
121
		var itemDetail = cartItems[sku.toString()];
130
		var itemDetail = cartItems[sku.toString()];
122
		if(itemDetail==undefined){
131
		if(itemDetail==undefined){
Line 128... Line 137...
128
			totalCartValue = totalCartValue + (unitPrice * newVal);
137
			totalCartValue = totalCartValue + (unitPrice * newVal);
129
			cartItems[sku.toString()]=itemDetail;
138
			cartItems[sku.toString()]=itemDetail;
130
		}else{
139
		}else{
131
			totalCartValue = totalCartValue - (cartItems[sku.toString()].quantity * cartItems[sku.toString()].unitprice) + (unitPrice * newVal);
140
			totalCartValue = totalCartValue - (cartItems[sku.toString()].quantity * cartItems[sku.toString()].unitprice) + (unitPrice * newVal);
132
			if(newVal==0){
141
			if(newVal==0){
133
				//$("div.cartdetailscard[data-id='"+sku+"']").parent().addClass('hidden');
142
				cartItems[sku.toString()].quantity = 0;
134
				//delete cartItems[sku.toString()];
143
				cartItems[sku.toString()].unitprice = unitPrice;
135
			}else{
144
			}else{
136
				cartItems[sku.toString()].quantity = newVal;
145
				cartItems[sku.toString()].quantity = newVal;
137
				cartItems[sku.toString()].unitprice = unitPrice;
146
				cartItems[sku.toString()].unitprice = unitPrice;
138
			}
147
			}
139
			
148
			
Line 148... Line 157...
148
			shippingCharges = 100;
157
			shippingCharges = 100;
149
		}
158
		}
150
		cartDetailsObj.shippingCharges = shippingCharges;
159
		cartDetailsObj.shippingCharges = shippingCharges;
151
		localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
160
		localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
152
	}
161
	}
153
	$('.cartitemstotal span.itemstotal').text('₹ '+numberWithCommas(totalCartValue));
162
	$('div.cartitemstotal span.itemstotal').text('₹ '+numberWithCommas(totalCartValue));
154
	$('.cartitemstotal span.shippingval').text('₹ '+numberWithCommas(shippingCharges));
163
	$('div.cartitemstotal span.shippingval').text('₹ '+numberWithCommas(shippingCharges));
155
	var payable = 0;
164
	var payable = 0;
156
	if(shippingCharges>0){
165
	if(shippingCharges>0){
157
		if(totalCartValue>0){
166
		if(totalCartValue>0){
158
			$('.cartitemstotal').removeClass('hidden');
167
			$('.cartitemstotal').removeClass('hidden');
159
			payable = parseInt(shippingCharges)+parseInt(totalCartValue);
168
			payable = parseInt(shippingCharges)+parseInt(totalCartValue);
-
 
169
		}else{
-
 
170
			payable = 0;
160
		}
171
		}
161
	}else{
172
	}else{
162
			payable = parseInt(totalCartValue);
173
			payable = parseInt(totalCartValue);
163
			$('.cartitemstotal').addClass('hidden');
174
			$('.cartitemstotal').addClass('hidden');
164
	}
175
	}
165
	$('.cartgrandtotal span.pull-right').text('₹ '+numberWithCommas(payable));
176
	$('div.cartgrandtotal span.pull-right').text('₹ '+numberWithCommas(payable));
-
 
177
	
-
 
178
	if(payable>0){
166
	localStorage.setItem('cart_details',JSON.stringify(cartDetailsObj));
179
		$('button.checkoutbtn').prop( "disabled", false );
-
 
180
	}else{
-
 
181
		$('button.checkoutbtn').prop( "disabled", true );
-
 
182
	}
167
});
183
});
168
 
184
 
169
function numberWithCommas(x) {
185
function numberWithCommas(x) {
170
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
186
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
171
}
187
}