Subversion Repositories SmartDukaan

Rev

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

Rev 1460 Rev 1463
Line 1... Line 1...
1
var totalAmount=0.00;
1
var totalAmount = 0.00;
-
 
2
 
2
$(document).ready(function(){
3
$(document).ready(function(){
3
 
4
 
4
  changeEstimate();
5
	changeEstimate();
5
	
6
 
6
  $('#cartTable td img.remove-quantitybttn').click(function(){
7
	$('#cartTable td img.remove-quantitybttn').click(function(){
7
    var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
8
		var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
8
    window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid="+prodID;
9
		window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid=" + prodID;
9
    /*
-
 
10
		Put Ajax call here
-
 
11
		To write the way to get itemid to be removed
-
 
12
		alert("Product with id " + prodID + " will be removed.");
-
 
13
		*/	
-
 
14
    //alert("AJAX request to remove products from Cart. Product ID: " + prodID);
-
 
15
    /*
-
 
16
    jQuery.ajax({
-
 
17
      type: "GET",
-
 
18
      url: "/cart/" + prodID + "?_method=delete",
-
 
19
      data: "productid="+prodID,
-
 
20
      success: function(msg){
-
 
21
        //alert( "Data Saved: " + msg );
-
 
22
        if(msg==1){
-
 
23
        // 	alert( "Deleted the item" );
-
 
24
        }else{
-
 
25
          //   	alert( "Not able to deleted the item" );
-
 
26
          return;
-
 
27
        }
-
 
28
        window.location.reload();  
-
 
29
      }
-
 
30
    });
-
 
31
    var $tr = $(this).parent().parent();
-
 
32
    var index = $tr.parent().children().index($tr);
-
 
33
    $(this).parent().parent().remove();
-
 
34
    var totalAmount=subtractionOfColumns("cartTable", 5, true);
-
 
35
    $("#totalAmount").html(totalAmount);
-
 
36
    */
-
 
37
  });
10
	});
38
}); 
11
});
39
 
12
 
40
function changeQty(obj,itempriceID,totalPriceID)	{
13
function changeQty(obj,itempriceID,totalPriceID)	{
41
	var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
14
	var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
42
	var quantity = parseInt(obj.value);
15
	var quantity = parseInt(obj.value);
43
	//alert("AJAX request to change product quantity in Cart. Product ID: " + prodID + " quantity: " + quantity);
-
 
44
 
16
 
45
	if (quantity > 5)	{
17
	if (quantity > 5)	{
46
		alert("You can not order more than 5 pieces of same product.");
18
		alert("You can not order more than 5 pieces of same product.");
47
		$(obj).focus();
19
		$(obj).focus();
48
	}
20
	}
Line 50... Line 22...
50
		jQuery.ajax({
22
		jQuery.ajax({
51
			type: "POST",
23
			type: "POST",
52
			url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
24
			url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
53
			data: "productid=" + prodID + "&quantity=" + quantity,
25
			data: "productid=" + prodID + "&quantity=" + quantity,
54
			success: function(msg){
26
			success: function(msg){
55
	/*			if(msg == 1)	{
-
 
56
					//   	alert( "Quantity Updates for the item" );
-
 
57
				} else	{
-
 
58
					// 	alert( "Not able to update the quantity for the item" );
-
 
59
					return;
-
 
60
				}*/
-
 
61
				window.location.reload();
27
				window.location.reload();
62
			}
28
			}
63
		});
29
		});
64
	}
30
	}
65
	
-
 
66
 
-
 
67
//	var val=document.getElementById(itempriceID).value;
-
 
68
//	var num = parseFloat(val.replace(/[^\d\.-]/g,''));
-
 
69
//	var qty=parseInt(obj.value);
-
 
70
//	var totalVal1=num*qty;
-
 
71
//	var formated_value = $().number_format(totalVal1, {
-
 
72
//		numberOfDecimals:2,
-
 
73
//		decimalSeparator: '.',
-
 
74
//		thousandSeparator: ',',
-
 
75
//		symbol: 'Rs. '
-
 
76
//	});
-
 
77
//	document.getElementById(totalPriceID).innerHTML=formated_value;
-
 
78
//	$("#totalAmount").html(sumOfColumns("cartTable", 5, true));
-
 
79
//	changeEstimate(prodID);
-
 
80
}
31
}
81
 
32
 
82
function sumOfColumns(tableID, columnIndex, hasHeader) {
33
function sumOfColumns(tableID, columnIndex, hasHeader)	{
83
  var tot = 0;
34
	var tot = 0;
84
  var inc=1;
35
	var inc = 1;
85
  var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
36
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
86
  var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
37
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
-
 
38
 
87
  tableChildren.each(function() {
39
	tableChildren.each(function() {
88
    var currentVal=document.getElementById('totalPrice'+inc).innerHTML;
40
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
89
    inc++;
41
		inc ++;
90
    var splitVal=currentVal.split("Rs.");
42
		var splitVal = currentVal.split("Rs.");
91
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
43
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
92
    tot += parseFloat(num);
44
		tot += parseFloat(num);
93
  });
45
	});
94
  totalAmount=tot;
46
	totalAmount = tot;
95
  var formated_value = $().number_format(tot, {
47
	var formated_value = $().number_format(tot, {
96
    numberOfDecimals:2,
48
		numberOfDecimals:2,
97
    decimalSeparator: '.',
49
		decimalSeparator: '.',
98
    thousandSeparator: ',',
50
		thousandSeparator: ',',
99
    symbol: 'Rs.'
51
		symbol: 'Rs.'
100
  });
52
	});
101
  return formated_value;
53
	return formated_value;
102
}
54
}
103
 
55
 
104
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
56
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
105
  var tot = 0;
57
	var tot = 0;
106
  $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
-
 
107
  .children("td:nth-child(" + columnIndex + ")")
-
 
108
  .each(function() {
-
 
109
    var currentVal=$(this).html();
-
 
110
    var splitVal=currentVal.split("Rs.");
-
 
111
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
-
 
112
    tot += parseInt(num);
-
 
113
  });
-
 
114
  var formated_value = $().number_format(tot, {
-
 
115
    numberOfDecimals:2,
-
 
116
    decimalSeparator: '.',
-
 
117
    thousandSeparator: ',',
-
 
118
    symbol: 'Rs.'
-
 
119
  });
-
 
120
  return formated_value;
-
 
121
}
-
 
122
 
58
 
123
function changeEstimate(item_id) {
59
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
124
  if(item_id == null ){
-
 
125
    //	alert("item id is null");
60
		var currentVal=$(this).html();
126
    for(var i=0; ; i++){
-
 
127
			
-
 
128
      var obj = $("#itemID"+(i+1));
61
		var splitVal=currentVal.split("Rs.");
129
//alert(obj);
-
 
130
      var itemId = $(obj).parent().parent().find("span.pro").attr("id");
62
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
131
      //	alert("item id is  " + itemId);
-
 
132
      if(itemId == null){
63
		tot += parseInt(num);
133
        break;
-
 
134
      }
64
	});
135
      changeEstimate(itemId);
-
 
136
    }
65
 
137
  }else{
-
 
138
    jQuery.ajax({
-
 
139
      type: "GET",
-
 
140
      url: "/estimate/"+$("#zipcode").val()+"_"+item_id,
66
	var formated_value = $().number_format(tot, {
141
      beforeSend: function(){
67
		numberOfDecimals: 2,
142
        $("#days"+"_"+item_id).html("<img src='/images/loader_l.gif'>"); 
-
 
143
      },
-
 
144
      success: function(msg){
68
		decimalSeparator: '.',
145
        //	alert( "delivery estimate is " + msg);
69
		thousandSeparator: ',',
146
        $("#shipping_time"+"_"+item_id).html(msg);
-
 
147
      }
70
		symbol: 'Rs.'
148
    });
71
	});
149
  }
72
	return formated_value;
150
}
73
}
-
 
74
 
-
 
75
function changeEstimate(item_id)	{
-
 
76
	if(item_id == null )	{
-
 
77
		for(var i = 0; ; i ++)	{
-
 
78
			var obj = $("#itemID" + (i + 1));
-
 
79
			var itemId = $(obj).parent().parent().find("span.pro").attr("id");
-
 
80
			if(itemId == null)	{
-
 
81
				break;
-
 
82
			}
-
 
83
			changeEstimate(itemId);
-
 
84
		}
-
 
85
	} else	{
-
 
86
		jQuery.ajax({
-
 
87
			type: "GET",
-
 
88
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
-
 
89
			beforeSend: function(){
-
 
90
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
-
 
91
			},
-
 
92
			success: function(msg){
-
 
93
				$("#shipping_time" + "_" + item_id).html(msg);
-
 
94
			}
-
 
95
		});
-
 
96
	}
-
 
97
}
151
98