Subversion Repositories SmartDukaan

Rev

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

var totalAmount=0.00;
$(document).ready(function(){

  changeEstimate();
        
  $('#cartTable td img.remove-quantitybttn').click(function(){
    var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
    window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid="+prodID;
    /*
                Put Ajax call here
                To write the way to get itemid to be removed
                alert("Product with id " + prodID + " will be removed.");
                */      
    //alert("AJAX request to remove products from Cart. Product ID: " + prodID);
    /*
    jQuery.ajax({
      type: "GET",
      url: "/cart/" + prodID + "?_method=delete",
      data: "productid="+prodID,
      success: function(msg){
        //alert( "Data Saved: " + msg );
        if(msg==1){
        //      alert( "Deleted the item" );
        }else{
          //    alert( "Not able to deleted the item" );
          return;
        }
        window.location.reload();  
      }
    });
    var $tr = $(this).parent().parent();
    var index = $tr.parent().children().index($tr);
    $(this).parent().parent().remove();
    var totalAmount=subtractionOfColumns("cartTable", 5, true);
    $("#totalAmount").html(totalAmount);
    */
  });
}); 

function changeQty(obj,itempriceID,totalPriceID)        {
        var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
        var quantity = parseInt(obj.value);
        //alert("AJAX request to change product quantity in Cart. Product ID: " + prodID + " quantity: " + quantity);

        jQuery.ajax({
                type: "POST",
                url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
                data: "productid=" + prodID + "&quantity=" + quantity,
                success: function(msg){
/*                      if(msg == 1)    {
                                //      alert( "Quantity Updates for the item" );
                        } else  {
                                //      alert( "Not able to update the quantity for the item" );
                                return;
                        }*/
                        window.location.reload();
                }
        });

//      var val=document.getElementById(itempriceID).value;
//      var num = parseFloat(val.replace(/[^\d\.-]/g,''));
//      var qty=parseInt(obj.value);
//      var totalVal1=num*qty;
//      var formated_value = $().number_format(totalVal1, {
//              numberOfDecimals:2,
//              decimalSeparator: '.',
//              thousandSeparator: ',',
//              symbol: 'Rs. '
//      });
//      document.getElementById(totalPriceID).innerHTML=formated_value;
//      $("#totalAmount").html(sumOfColumns("cartTable", 5, true));
//      changeEstimate(prodID);
}

function sumOfColumns(tableID, columnIndex, hasHeader) {
  var tot = 0;
  var inc=1;
  var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
  var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
  tableChildren.each(function() {
    var currentVal=document.getElementById('totalPrice'+inc).innerHTML;
    inc++;
    var splitVal=currentVal.split("Rs.");
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
    tot += parseFloat(num);
  });
  totalAmount=tot;
  var formated_value = $().number_format(tot, {
    numberOfDecimals:2,
    decimalSeparator: '.',
    thousandSeparator: ',',
    symbol: 'Rs.'
  });
  return formated_value;
}

function subtractionOfColumns(tableID, columnIndex, hasHeader) {
  var tot = 0;
  $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""))
  .children("td:nth-child(" + columnIndex + ")")
  .each(function() {
    var currentVal=$(this).html();
    var splitVal=currentVal.split("Rs.");
    var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
    tot += parseInt(num);
  });
  var formated_value = $().number_format(tot, {
    numberOfDecimals:2,
    decimalSeparator: '.',
    thousandSeparator: ',',
    symbol: 'Rs.'
  });
  return formated_value;
}

function changeEstimate(item_id) {
  if(item_id == null ){
    //  alert("item id is null");
    for(var i=0; ; i++){
                        
      var obj = $("#itemID"+(i+1));
//alert(obj);
      var itemId = $(obj).parent().parent().find("span.pro").attr("id");
      //        alert("item id is  " + itemId);
      if(itemId == null){
        break;
      }
      changeEstimate(itemId);
    }
  }else{
    jQuery.ajax({
      type: "GET",
      url: "/estimate/"+$("#zipcode").val()+"_"+item_id,
      beforeSend: function(){
        $("#days"+"_"+item_id).html("<img src='/images/loader_l.gif'>"); 
      },
      success: function(msg){
        //      alert( "delivery estimate is " + msg);
        $("#shipping_time"+"_"+item_id).html(msg);
      }
    });
  }
}