Blame view

web/js/order.js 2.99 KB
2a050410   Yarik   Order
1
2
3
4
  $(function() {
      $(document)
          .on('click', '.remove-order-product', function(e) {
              e.preventDefault();
1821d077   Anastasia   change order price
5
6
              var current_price = parseInt($(this).parents('.row-order-product').data('price'));
              var number = parseInt($(this).parents('.row-order-product').children('.col-md-3').children('.form-group').children('input').val());
b6db17e5   Anastasia   order in admin
7
8
9
10
              var id = $(this)
                  .data('id');
              var variant = $(this)
                  .data('variant');
543a6adb   Anastasia   order
11
12
13
14
15
16
17
18
19
20
21
              $(this)
                  .parents('.row-order-product')
                  .remove();
              var total_price = parseInt($(".sum_all")
                  .children('p')
                  .text());
              total_price = total_price - (current_price * number);
              console.log(number);
              $(".sum_all")
                  .children('p')
                  .text(total_price);
2a050410   Yarik   Order
22
          });
7f07c94f   Виталий   categories create
23
24
25
26
27
28
29
30
      $('#count-to-order').keypress(function(e) {
          if (!(e.which==8 ||(e.which>47 && e.which<58))) return false;
      });
      $('#count-to-order').change(function(e) {
          if ($(this).val() <= 0) {
              $(this).val('1')
          }
      });
fd40a9e1   Yarik   Products to order
31
32
33
34
35
36
37
      $(document)
          .on('click', '.variant-to-order', function(e) {
              e.preventDefault();
              var id = $('#add-to-order');
              var count = $('#count-to-order');
              var order = $(this)
                  .data('id');
7f07c94f   Виталий   categories create
38
39
40
41
42
43
44
45
46
              if (id.val() ) {
                  if(count.val()<=0) {
                      var newCountVal = count.val();
                  } else {
                      var newCountVal = 1;
                  }
  
                  $('.order-goods-th').css({display:'block'});
  
fd40a9e1   Yarik   Products to order
47
48
                  $.post('/admin/order/add-to-order', {
                      id: id.val(),
7f07c94f   Виталий   categories create
49
                      count: newCountVal,
fd40a9e1   Yarik   Products to order
50
                      order: order
1228053e   Anastasia   event order
51
                  }, function(data) {
543a6adb   Anastasia   order
52
                      if (data.success) {
543a6adb   Anastasia   order
53
54
55
56
57
                          var sum = $(".sum_all")
                              .children('p')
                              .text();
                          $(".sum_all")
                              .children('p')
8b638e12   Anastasia   sum in order
58
59
60
                              .html(parseInt(sum) + parseInt(data.price));
                          $('#product-rows')
                              .append(data.row);
7f07c94f   Виталий   categories create
61
                          $('#add-to-order').select2("val", "");
543a6adb   Anastasia   order
62
                      }
1228053e   Anastasia   event order
63
  
fd40a9e1   Yarik   Products to order
64
                  });
fd40a9e1   Yarik   Products to order
65
66
              }
          });
1821d077   Anastasia   change order price
67
68
      $(document).on('change', '.count', function() {
          var count_old = parseInt(this.defaultValue);
8b638e12   Anastasia   sum in order
69
          console.log(count_old);
1821d077   Anastasia   change order price
70
71
72
73
74
75
76
          var count_new = parseInt(this.value);
          var current_price = parseInt($(this).parents('.row-order-product').data('price'));
          var total_price = parseInt($(".sum_all").children('p').text());
          total_price = total_price - (count_old * current_price) + (count_new * current_price);
          this.defaultValue = this.value;
          $(".sum_all").children('p').text(total_price);
      })
fd40a9e1   Yarik   Products to order
77
78
79
80
81
  });
  function showLoader(container) {
      $(container)
          .prepend('<div class="loader-wrapper"></div>');
  }