Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
794 rajveer 1
var totalAmount=0.00;
2
$(document).ready(function(){
801 rajveer 3
 
4
  changeEstimate();
5
 
794 rajveer 6
  $('#cartTable td img.remove-quantitybttn').click(function(){
801 rajveer 7
    var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
8
    window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid="+prodID;
794 rajveer 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
		*/	
801 rajveer 14
    //alert("AJAX request to remove products from Cart. Product ID: " + prodID);
15
    /*
794 rajveer 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);
801 rajveer 36
    */
794 rajveer 37
  });
38
}); 
1190 varun.gupt 39
 
40
function changeQty(obj,itempriceID,totalPriceID)	{
41
	var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
42
	var quantity = parseInt(obj.value);
43
	//alert("AJAX request to change product quantity in Cart. Product ID: " + prodID + " quantity: " + quantity);
44
 
45
	jQuery.ajax({
46
		type: "POST",
47
		url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
48
		data: "productid=" + prodID + "&quantity=" + quantity,
49
		success: function(msg){
50
/*			if(msg == 1)	{
51
				//   	alert( "Quantity Updates for the item" );
52
			} else	{
53
				// 	alert( "Not able to update the quantity for the item" );
54
				return;
55
			}*/
56
			window.location.reload();
57
		}
58
	});
59
 
60
//	var val=document.getElementById(itempriceID).value;
61
//	var num = parseFloat(val.replace(/[^\d\.-]/g,''));
62
//	var qty=parseInt(obj.value);
63
//	var totalVal1=num*qty;
64
//	var formated_value = $().number_format(totalVal1, {
65
//		numberOfDecimals:2,
66
//		decimalSeparator: '.',
67
//		thousandSeparator: ',',
68
//		symbol: 'Rs. '
69
//	});
70
//	document.getElementById(totalPriceID).innerHTML=formated_value;
71
//	$("#totalAmount").html(sumOfColumns("cartTable", 5, true));
72
//	changeEstimate(prodID);
794 rajveer 73
}
74
 
75
function sumOfColumns(tableID, columnIndex, hasHeader) {
76
  var tot = 0;
77
  var inc=1;
1048 chandransh 78
  var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
79
  var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
80
  tableChildren.each(function() {
794 rajveer 81
    var currentVal=document.getElementById('totalPrice'+inc).innerHTML;
82
    inc++;
83
    var splitVal=currentVal.split("Rs.");
84
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
85
    tot += parseFloat(num);
86
  });
87
  totalAmount=tot;
88
  var formated_value = $().number_format(tot, {
89
    numberOfDecimals:2,
90
    decimalSeparator: '.',
91
    thousandSeparator: ',',
92
    symbol: 'Rs.'
93
  });
94
  return formated_value;
95
}
96
 
97
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
98
  var tot = 0;
99
  $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
100
  .children("td:nth-child(" + columnIndex + ")")
101
  .each(function() {
102
    var currentVal=$(this).html();
103
    var splitVal=currentVal.split("Rs.");
104
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
105
    tot += parseInt(num);
106
  });
107
  var formated_value = $().number_format(tot, {
108
    numberOfDecimals:2,
109
    decimalSeparator: '.',
110
    thousandSeparator: ',',
111
    symbol: 'Rs.'
112
  });
113
  return formated_value;
114
}
115
 
116
function changeEstimate(item_id) {
117
  if(item_id == null ){
118
    //	alert("item id is null");
119
    for(var i=0; ; i++){
120
 
121
      var obj = $("#itemID"+(i+1));
801 rajveer 122
//alert(obj);
123
      var itemId = $(obj).parent().parent().find("span.pro").attr("id");
794 rajveer 124
      //	alert("item id is  " + itemId);
125
      if(itemId == null){
126
        break;
127
      }
1048 chandransh 128
      changeEstimate(itemId);
794 rajveer 129
    }
130
  }else{
131
    jQuery.ajax({
132
      type: "GET",
133
      url: "/estimate/"+$("#zipcode").val()+"_"+item_id,
134
      beforeSend: function(){
135
        $("#days"+"_"+item_id).html("<img src='/images/loader_l.gif'>"); 
136
      },
137
      success: function(msg){
138
        //	alert( "delivery estimate is " + msg);
139
        $("#shipping_time"+"_"+item_id).html(msg);
140
      }
141
    });
142
  }
143
}