Subversion Repositories SmartDukaan

Rev

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

Rev 2696 Rev 3830
Line 1... Line 1...
1
var totalAmount = 0.00;
1
var totalAmount = 0.00;
2
 
2
 
3
$(document).ready(function(){
3
$(document).ready(function(){
4
 
4
 
5
	changeEstimate();
5
	changeEstimate();
-
 
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
	});
6
 
25
 
7
	$('#cartTable td img.remove-quantitybttn').click(function(){
26
	$('#cart .remove-quantitybttn').click(function(){
8
		var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
27
		var itemId = $(this).attr('id').split('_')[1];
9
		window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid=" + prodID;
28
		window.location.href = "/cart/"  + itemId + "?_method=delete" + "&productid=" + itemId;
-
 
29
	});
-
 
30
	
-
 
31
	$('#computeEstimate').click(function(){
-
 
32
		changeEstimate();
10
	});
33
	});
11
	
34
	
12
	$('#applyCoupon').click(function(){
35
	$('#applyCoupon').click(function(){
13
		$('#couponAction').val('applycoupon');
36
		$('#couponAction').val('applycoupon');
14
		$('#frmCouponCode').submit();
37
		$('#frmCouponCode').submit();
Line 16... Line 39...
16
	
39
	
17
	$('#removeCoupon').click(function(){
40
	$('#removeCoupon').click(function(){
18
		$('#couponAction').val('removecoupon');
41
		$('#couponAction').val('removecoupon');
19
		$('#frmCouponCode').submit();
42
		$('#frmCouponCode').submit();
20
	});
43
	});
21
});
-
 
22
 
44
	
23
function changeQty(obj,itempriceID,totalPriceID)	{
45
	$('.cart-item-quantity').change(function(){
24
	var prodID = $(obj).parent().parent().parent().parent().children().find("span.pro").attr("id");
46
		var itemId = $(this).attr("id").split('_')[1];
25
	var quantity = parseInt(obj.value);
47
		var quantity = parseInt($(this).val());
26
 
48
		
27
	if (quantity > 5)	{
49
		if (quantity > 5)	{
28
		alert("You can not order more than 5 pieces of same product.");
50
			alert("You can not order more than 5 pieces of same product.");
29
		$(obj).focus();
51
			$(obj).focus();
30
	}
52
		}
31
	else	{
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
		
32
		jQuery.ajax({
85
		jQuery.ajax({
33
			type: "POST",
86
			type: "POST",
34
			url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
87
			url: "/address",
35
			data: "productid=" + prodID + "&quantity=" + quantity,
88
			data: "action=delete&addressid=" + addressId,
36
			success: function(msg){
89
			success: function(msg){
37
				window.location.reload();
90
				window.location.reload();
38
			}
91
			}
39
		});
92
		});
-
 
93
	});
-
 
94
	
-
 
95
	function checkIfUserHasAddress()	{
-
 
96
		var addressEmpty = parseInt($('#addressEmpty').val());
-
 
97
		
-
 
98
		if (addressEmpty == 1)	{
-
 
99
			showAddAddressForm();
-
 
100
		}
40
	}
101
	}
-
 
102
	
-
 
103
	function showAddAddressForm(){
-
 
104
		$('#addresses').hide();
-
 
105
		$('#frmShippingAddress').show();
41
}
106
	}
-
 
107
	
-
 
108
	function showAddressList()	{
-
 
109
		$('#frmShippingAddress').hide();
-
 
110
		$('#addresses').show();
-
 
111
	}
-
 
112
});
42
 
113
 
43
function sumOfColumns(tableID, columnIndex, hasHeader)	{
114
function sumOfColumns(tableID, columnIndex, hasHeader)	{
44
	var tot = 0;
115
	var tot = 0;
45
	var inc = 1;
116
	var inc = 1;
46
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
117
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
Line 82... Line 153...
82
	return formated_value;
153
	return formated_value;
83
}
154
}
84
 
155
 
85
function changeEstimate(item_id)	{
156
function changeEstimate(item_id)	{
86
	if(item_id == null )	{
157
	if(item_id == null )	{
87
		for(var i = 0; ; i ++)	{
-
 
88
			var obj = $("#itemID" + (i + 1));
158
		$("#cartDetail tbody tr").each(function(index, item){
89
			var itemId = $(obj).parent().parent().find("span.pro").attr("id");
159
			var itemId = $(item).attr("id");
90
			if(itemId == null)	{
-
 
91
				break;
-
 
92
			}
-
 
93
			changeEstimate(itemId);
160
			changeEstimate(itemId);
-
 
161
		});
94
		}
162
		
95
	} else	{
163
	} else	{
96
		jQuery.ajax({
164
		jQuery.ajax({
97
			type: "GET",
165
			type: "GET",
98
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
166
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
99
			beforeSend: function(){
167
			beforeSend: function(){
100
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
168
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
-
 
169
				$("#shipping_time_" + item_id).html('<img src="/images/loader_l.gif">');
101
			},
170
			},
102
			success: function(msg){
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)	{
103
				$("#shipping_time" + "_" + item_id).html(msg);
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
				}
104
			}
184
			}
105
		});
185
		});
106
	}
186
	}
107
}
187
}
108
188