Subversion Repositories SmartDukaan

Rev

Rev 5831 | Rev 6903 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1463 varun.gupt 1
var totalAmount = 0.00;
2
 
794 rajveer 3
$(document).ready(function(){
801 rajveer 4
 
3830 chandransh 5
	checkIfUserHasAddress();
6561 amit.gupta 6
	if(window.location.pathname === "/cart") {
7
		changeEstimate();
8
	}
4453 varun.gupt 9
	$('#checkout').click(function(){
3830 chandransh 10
		window.location.href = "/shipping";
11
	});
12
 
4453 varun.gupt 13
	$('#poplogin').click(function(){
4222 varun.gupt 14
		$.colorbox({
15
    		width: "860px",
4458 varun.gupt 16
    		height: "340px",
4222 varun.gupt 17
    		iframe: false,
18
    		href: "/login-mini",
19
 
20
    		onComplete: function(){
4372 varun.gupt 21
    			trackEventWithGA('Cart', 'Login/Register Popup', '');
4222 varun.gupt 22
    		}
23
    	});
24
	});
25
 
3830 chandransh 26
	$('#proceedToPay').click(function(){
5748 anupam.sin 27
		if(($('#store-addresses').find('.default-address').attr('zone') !=  $('#zone-selector').val()) && ($("#tabSelector").val() == "HotSpot")) {
5747 anupam.sin 28
			alert("Please select one store address");
29
			return false;
30
		}
4222 varun.gupt 31
		var canProceedToPay = parseInt($('#canProceedToPay').val());
3830 chandransh 32
 
33
		if (canProceedToPay == 1)	{
34
 
35
			trackProceedToPay();
36
			$('#formProceedToPay').submit();
37
		} else	{
5040 varun.gupt 38
			var reasonActionDisability = $('#reasonActionDisability').val();
3830 chandransh 39
 
5040 varun.gupt 40
			if(reasonActionDisability.indexOf('Location not serviceable') >= 0)	{
41
				trackEventWithGA('Cart', 'Location not serviceable', $('#selectedPincode').val());
42
			}
5831 anupam.sin 43
			else if (($("#tabSelector").val() == "HotSpot")) {
44
				reasonActionDisability = 'Please enter an address which will be printed on the bill';
45
			} else {
46
				reasonActionDisability = 'Please specify a delivery address';
47
			}
5040 varun.gupt 48
			alert(reasonActionDisability);
3830 chandransh 49
		}
50
	});
4791 varun.gupt 51
 
52
	$('#viewOrders').click(function(){
53
		window.location.href = "/myaccount";
54
	});
1190 varun.gupt 55
 
3830 chandransh 56
	$('#cart .remove-quantitybttn').click(function(){
57
		var itemId = $(this).attr('id').split('_')[1];
58
		window.location.href = "/cart/"  + itemId + "?_method=delete" + "&productid=" + itemId;
1463 varun.gupt 59
	});
1981 varun.gupt 60
 
3830 chandransh 61
	$('#computeEstimate').click(function(){
62
		changeEstimate();
3941 varun.gupt 63
		$('#cartDetail').find('thead .dev-pincode').html($('#zipcode').val());
3830 chandransh 64
	});
65
 
1981 varun.gupt 66
	$('#applyCoupon').click(function(){
67
		$('#couponAction').val('applycoupon');
68
		$('#frmCouponCode').submit();
69
	});
70
 
71
	$('#removeCoupon').click(function(){
72
		$('#couponAction').val('removecoupon');
73
		$('#frmCouponCode').submit();
74
	});
3830 chandransh 75
 
76
	$('.cart-item-quantity').change(function(){
77
		var itemId = $(this).attr("id").split('_')[1];
78
		var quantity = parseInt($(this).val());
79
 
80
		if (quantity > 5)	{
81
			alert("You can not order more than 5 pieces of same product.");
82
			$(obj).focus();
83
		}
84
		else	{
85
			jQuery.ajax({
86
				type: "POST",
87
				url: "/cart/" + itemId + "?_method=put&productid=" + itemId + "&quantity=" + quantity,
88
				data: "productid=" + itemId + "&quantity=" + quantity,
89
				success: function(msg){
90
					window.location.reload();
91
				}
92
			});
93
		}
94
	});
95
 
96
	$('#submitAddress').click(function(){
97
		$('#frmShippingAddress').submit();
98
	});
99
 
4325 mandeep.dh 100
	$('#addAddress').live('click', function(){
3830 chandransh 101
		showAddAddressForm();
102
	});
4325 mandeep.dh 103
 
104
	$('#closeAddAddressForm').live('click', function() {
3830 chandransh 105
		showAddressList();
106
	});
107
 
108
	$('#addresses .button-address-select').click(function(){
109
		var addressId = $(this).attr('id').split('_')[1];
110
		$('#formChangeAddressTo_' + addressId).submit();
111
	});
112
 
5716 anupam.sin 113
	function checkIfUserHasAddress(){
3830 chandransh 114
		var addressEmpty = parseInt($('#addressEmpty').val());
115
 
116
		if (addressEmpty == 1)	{
117
			showAddAddressForm();
118
		}
1460 varun.gupt 119
	}
3830 chandransh 120
 
121
	function showAddAddressForm(){
5716 anupam.sin 122
		//$('#main-right-container').hide();
123
		$('#shipping-address-div').hide();
124
		$('#billing-address-div').hide();
3830 chandransh 125
		$('#frmShippingAddress').show();
126
	}
127
 
128
	function showAddressList()	{
129
		$('#frmShippingAddress').hide();
5716 anupam.sin 130
		//$('#main-right-container').show();
5831 anupam.sin 131
		if($("#tabSelector").val() == "HotSpot") {
132
			$('#billing-address-div').show();
133
		} else {
134
			$('#shipping-address-div').show();
135
		}
3830 chandransh 136
	}
137
});
794 rajveer 138
 
1463 varun.gupt 139
function sumOfColumns(tableID, columnIndex, hasHeader)	{
140
	var tot = 0;
141
	var inc = 1;
142
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
143
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
144
 
145
	tableChildren.each(function() {
146
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
147
		inc ++;
148
		var splitVal = currentVal.split("Rs.");
149
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
150
		tot += parseFloat(num);
151
	});
152
	totalAmount = tot;
153
	var formated_value = $().number_format(tot, {
154
		numberOfDecimals:2,
155
		decimalSeparator: '.',
156
		thousandSeparator: ',',
157
		symbol: 'Rs.'
158
	});
159
	return formated_value;
794 rajveer 160
}
161
 
162
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
1463 varun.gupt 163
	var tot = 0;
164
 
165
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
166
		var currentVal=$(this).html();
167
		var splitVal=currentVal.split("Rs.");
168
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
169
		tot += parseInt(num);
170
	});
171
 
172
	var formated_value = $().number_format(tot, {
173
		numberOfDecimals: 2,
174
		decimalSeparator: '.',
175
		thousandSeparator: ',',
176
		symbol: 'Rs.'
177
	});
178
	return formated_value;
794 rajveer 179
}
180
 
1463 varun.gupt 181
function changeEstimate(item_id)	{
182
	if(item_id == null )	{
3830 chandransh 183
		$("#cartDetail tbody tr").each(function(index, item){
184
			var itemId = $(item).attr("id");
1463 varun.gupt 185
			changeEstimate(itemId);
3830 chandransh 186
		});
187
 
1463 varun.gupt 188
	} else	{
189
		jQuery.ajax({
190
			type: "GET",
191
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
192
			beforeSend: function(){
6561 amit.gupta 193
				$("#img" + "_" + item_id).html("<img src='/images/loader_l.gif'>").show();
194
				$("#block" + "_" + item_id).hide();
195
				$("#serv_" + item_id).hide();
1463 varun.gupt 196
			},
3830 chandransh 197
			success: function(data){
6561 amit.gupta 198
				$("#img" + "_" + item_id).html("<img src='/images/loader_l.gif'>").hide();
3830 chandransh 199
				var response = eval('(' + data + ')');
200
				var deliveryEstimate = parseInt(response['delivery_estimate']);
6561 amit.gupta 201
				var otg= response['on_time_guarantee'];
3830 chandransh 202
 
203
				if(deliveryEstimate == -1)	{
6561 amit.gupta 204
					$("#serv_" + item_id).show();
205
					return;
3830 chandransh 206
 
207
				} else if(deliveryEstimate == 1)	{
6561 amit.gupta 208
					$("#days_" + item_id).html('1 Business Day');
3830 chandransh 209
				}
210
				else	{
6561 amit.gupta 211
					$("#days_" + item_id).html(deliveryEstimate + ' Business Days');
3830 chandransh 212
				}
6561 amit.gupta 213
				if(otg == "true")	{
214
					$("#otg_" + item_id).show();
215
				} else {
216
					$("#otg_" + item_id).hide();
217
				}
218
				$("#block" + "_" + item_id).show();
1463 varun.gupt 219
			}
220
		});
221
	}
222
}