selimppc

cart_script

Mar 21st, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.  
  3.     $("#sell").click(function(e) {
  4.         var check   =  $("#isempty").val();
  5.         if(check!='1'){
  6.             alert("Add Products to Cart First");
  7.         }
  8.     });
  9.     $("#add_cart").click(function(e){
  10.         e.preventDefault();
  11.         $("#isempty").val('1');
  12.         var price           = $("#unit_price").val();
  13.         var customer        = $("#customer_id").val();
  14.         var quantity        = $("#total_quantity").val();
  15.         var total           = $("#total_price").val();
  16.         var warehouse_id    = $("#warehouse_id").val();
  17.         var warehouse       = $("#warehouse_id option:selected").text();
  18.         var product_id      = $("#item_id").val();
  19.         var product         = $("#item_id option:selected").text();
  20.  
  21.         var category_id     = $("#catagory_id").val();
  22.         var category        = $("#catagory_id option:selected").text();
  23.  
  24.         var sub_total       = $("#sub_total").val();
  25.  
  26.         var numsubtotal     = parseInt(sub_total) + parseInt(total);
  27.  
  28.         var cart_item   = '';
  29.         cart_item += '<tr id="tablerow">';
  30.         cart_item += '<td>' + warehouse + '<input type="hidden" class="form-control" name="warehouse[]" value="'+warehouse_id+'"></td>';
  31.         cart_item += '<td>' + product + '<input type="hidden" class="form-control" name="item[]" value="'+product_id+'" readonly></td>';
  32.         cart_item += '<td>' + category + '<input type="hidden" class="form-control" name="category[]" value="'+category_id+'" readonly></td>';
  33.         cart_item += '<td>' + quantity + '<input type="hidden" class="form-control" name="quantity[]" value="'+quantity+'" readonly></td>';
  34.         cart_item += '<td>' + price + '<input type="hidden" class="form-control" name="price[]" value="'+price+'" readonly></td>';
  35.         cart_item += '<td>' + total + '<input type="hidden" class="form-control" id="cart_total" name="total[]" value="'+total+'" readonly></td>';
  36.         cart_item += '<td><a href="#" style="margin-left: 20px;" class="remove_field btn btn-rounded btn-inline btn-danger"><span class="glyphicon">&#xe088;</span></a></td>';
  37.  
  38.         cart_item += '</tr>';
  39.         $(".cart").append(cart_item);
  40.         $('option').prop('selected', function() {
  41.             return this.defaultSelected;
  42.         });
  43.         $('.fields').find('input:text').val('');
  44.         $("#customer_id").val(customer);
  45.         $("#sub_total").val(numsubtotal);
  46.  
  47.  
  48.     });
  49.     $(".cart").on("click",".remove_field", function(e){
  50.         e.preventDefault();
  51.         var minustotal      = $(this).closest("#tablerow").find("input[id='cart_total']").val();
  52.         var intmintotal = parseInt(minustotal);
  53.         var sub_total       = $("#sub_total").val();
  54.         var numsubtotal     = parseInt(sub_total) - parseInt(intmintotal);
  55.         $("#sub_total").val(numsubtotal);
  56.         $(this).closest('#tablerow').remove();
  57.  
  58.     })
  59. });
Add Comment
Please, Sign In to add comment