Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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
}); 
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
      //  alert( "Data Saved: " + msg );
51
      if(msg==1){
52
      //   	alert( "Quantity Updates for the item" );
53
      }else{
54
        // 	alert( "Not able to update the quantity for the item" );
55
        return;
56
      }
57
      window.location.reload();
58
    }
59
  });
60
 
61
  var val=document.getElementById(itempriceID).value;
62
  var num = parseFloat(val.replace(/[^\d\.-]/g,''));
63
  var qty=parseInt(obj.value);
64
  var totalVal1=num*qty;
65
  var formated_value = $().number_format(totalVal1, {
66
    numberOfDecimals:2,
67
    decimalSeparator: '.',
68
    thousandSeparator: ',',
69
    symbol: 'Rs. '
70
  });
71
  document.getElementById(totalPriceID).innerHTML=formated_value;	
72
  $("#totalAmount").html(sumOfColumns("cartTable", 5, true));
73
 
74
  changeEstimate(prodID);
75
}
76
 
77
function sumOfColumns(tableID, columnIndex, hasHeader) {
78
  var tot = 0;
79
  var inc=1;
80
  $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
81
  .children("td:nth-child(" + columnIndex + ")")
82
  .each(function() {
83
    var currentVal=document.getElementById('totalPrice'+inc).innerHTML;
84
    inc++;
85
    var splitVal=currentVal.split("Rs.");
86
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
87
    tot += parseFloat(num);
88
  });
89
  totalAmount=tot;
90
  var formated_value = $().number_format(tot, {
91
    numberOfDecimals:2,
92
    decimalSeparator: '.',
93
    thousandSeparator: ',',
94
    symbol: 'Rs.'
95
  });
96
  return formated_value;
97
}
98
 
99
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
100
  var tot = 0;
101
  $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
102
  .children("td:nth-child(" + columnIndex + ")")
103
  .each(function() {
104
    var currentVal=$(this).html();
105
    var splitVal=currentVal.split("Rs.");
106
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
107
    tot += parseInt(num);
108
  });
109
  var formated_value = $().number_format(tot, {
110
    numberOfDecimals:2,
111
    decimalSeparator: '.',
112
    thousandSeparator: ',',
113
    symbol: 'Rs.'
114
  });
115
  return formated_value;
116
}
117
 
118
function changeEstimate(item_id) {
119
  if(item_id == null ){
120
    //	alert("item id is null");
121
    for(var i=0; ; i++){
122
 
123
      var obj = $("#itemID"+(i+1));
801 rajveer 124
//alert(obj);
125
      var itemId = $(obj).parent().parent().find("span.pro").attr("id");
794 rajveer 126
      //	alert("item id is  " + itemId);
127
      if(itemId == null){
128
        break;
129
      }
130
      changeEstimate(itemId)
131
    }
132
  }else{
133
    jQuery.ajax({
134
      type: "GET",
135
      url: "/estimate/"+$("#zipcode").val()+"_"+item_id,
136
      beforeSend: function(){
137
        $("#days"+"_"+item_id).html("<img src='/images/loader_l.gif'>"); 
138
      },
139
      success: function(msg){
140
        //	alert( "delivery estimate is " + msg);
141
        $("#shipping_time"+"_"+item_id).html(msg);
142
      }
143
    });
144
  }
145
}