Subversion Repositories SmartDukaan

Rev

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