Subversion Repositories SmartDukaan

Rev

Rev 2696 | Rev 3881 | 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
 
1463 varun.gupt 5
	changeEstimate();
3830 chandransh 6
 
7
	checkIfUserHasAddress();
8
 
9
	$('#checkout').click(function(){
10
		window.location.href = "/shipping";
11
	});
12
 
13
	$('#proceedToPay').click(function(){
14
		var canProceedToPay = parseInt($('#canProceedToPay').val())
15
 
16
		if (canProceedToPay == 1)	{
17
 
18
			trackProceedToPay();
19
			$('#formProceedToPay').submit();
20
		} else	{
21
 
22
			alert($('#reasonActionDisability').val());
23
		}
24
	});
1190 varun.gupt 25
 
3830 chandransh 26
	$('#cart .remove-quantitybttn').click(function(){
27
		var itemId = $(this).attr('id').split('_')[1];
28
		window.location.href = "/cart/"  + itemId + "?_method=delete" + "&productid=" + itemId;
1463 varun.gupt 29
	});
1981 varun.gupt 30
 
3830 chandransh 31
	$('#computeEstimate').click(function(){
32
		changeEstimate();
33
	});
34
 
1981 varun.gupt 35
	$('#applyCoupon').click(function(){
36
		$('#couponAction').val('applycoupon');
37
		$('#frmCouponCode').submit();
38
	});
39
 
40
	$('#removeCoupon').click(function(){
41
		$('#couponAction').val('removecoupon');
42
		$('#frmCouponCode').submit();
43
	});
3830 chandransh 44
 
45
	$('.cart-item-quantity').change(function(){
46
		var itemId = $(this).attr("id").split('_')[1];
47
		var quantity = parseInt($(this).val());
48
 
49
		if (quantity > 5)	{
50
			alert("You can not order more than 5 pieces of same product.");
51
			$(obj).focus();
52
		}
53
		else	{
54
			jQuery.ajax({
55
				type: "POST",
56
				url: "/cart/" + itemId + "?_method=put&productid=" + itemId + "&quantity=" + quantity,
57
				data: "productid=" + itemId + "&quantity=" + quantity,
58
				success: function(msg){
59
					window.location.reload();
60
				}
61
			});
62
		}
63
	});
64
 
65
	$('#submitAddress').click(function(){
66
		$('#frmShippingAddress').submit();
67
	});
68
 
69
	$('#addAddress').click(function(){
70
		showAddAddressForm();
71
	});
72
 
73
	$('#closeAddAddressForm').click(function(){
74
		showAddressList();
75
	});
76
 
77
	$('#addresses .button-address-select').click(function(){
78
		var addressId = $(this).attr('id').split('_')[1];
79
		$('#formChangeAddressTo_' + addressId).submit();
80
	});
81
 
82
	$('#addresses .delete-address').click(function(){
83
		var addressId = $(this).attr('id').split('_')[1];
84
 
1460 varun.gupt 85
		jQuery.ajax({
86
			type: "POST",
3830 chandransh 87
			url: "/address",
88
			data: "action=delete&addressid=" + addressId,
1460 varun.gupt 89
			success: function(msg){
90
				window.location.reload();
91
			}
92
		});
3830 chandransh 93
	});
94
 
95
	function checkIfUserHasAddress()	{
96
		var addressEmpty = parseInt($('#addressEmpty').val());
97
 
98
		if (addressEmpty == 1)	{
99
			showAddAddressForm();
100
		}
1460 varun.gupt 101
	}
3830 chandransh 102
 
103
	function showAddAddressForm(){
104
		$('#addresses').hide();
105
		$('#frmShippingAddress').show();
106
	}
107
 
108
	function showAddressList()	{
109
		$('#frmShippingAddress').hide();
110
		$('#addresses').show();
111
	}
112
});
794 rajveer 113
 
1463 varun.gupt 114
function sumOfColumns(tableID, columnIndex, hasHeader)	{
115
	var tot = 0;
116
	var inc = 1;
117
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
118
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
119
 
120
	tableChildren.each(function() {
121
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
122
		inc ++;
123
		var splitVal = currentVal.split("Rs.");
124
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
125
		tot += parseFloat(num);
126
	});
127
	totalAmount = tot;
128
	var formated_value = $().number_format(tot, {
129
		numberOfDecimals:2,
130
		decimalSeparator: '.',
131
		thousandSeparator: ',',
132
		symbol: 'Rs.'
133
	});
134
	return formated_value;
794 rajveer 135
}
136
 
137
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
1463 varun.gupt 138
	var tot = 0;
139
 
140
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
141
		var currentVal=$(this).html();
142
		var splitVal=currentVal.split("Rs.");
143
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
144
		tot += parseInt(num);
145
	});
146
 
147
	var formated_value = $().number_format(tot, {
148
		numberOfDecimals: 2,
149
		decimalSeparator: '.',
150
		thousandSeparator: ',',
151
		symbol: 'Rs.'
152
	});
153
	return formated_value;
794 rajveer 154
}
155
 
1463 varun.gupt 156
function changeEstimate(item_id)	{
157
	if(item_id == null )	{
3830 chandransh 158
		$("#cartDetail tbody tr").each(function(index, item){
159
			var itemId = $(item).attr("id");
1463 varun.gupt 160
			changeEstimate(itemId);
3830 chandransh 161
		});
162
 
1463 varun.gupt 163
	} else	{
164
		jQuery.ajax({
165
			type: "GET",
166
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
167
			beforeSend: function(){
168
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
3830 chandransh 169
				$("#shipping_time_" + item_id).html('<img src="/images/loader_l.gif">');
1463 varun.gupt 170
			},
3830 chandransh 171
			success: function(data){
172
				var response = eval('(' + data + ')');
173
				var deliveryEstimate = parseInt(response['delivery_estimate']);
174
 
175
				if(deliveryEstimate == -1)	{
176
					$("#shipping_time_" + item_id).html('Location is not serviceable');
177
 
178
				} else if(deliveryEstimate == 1)	{
179
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in 1 Business Day');
180
				}
181
				else	{
182
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in ' + deliveryEstimate + ' Business Days');
183
				}
1463 varun.gupt 184
			}
185
		});
186
	}
187
}