Commit 1821d0774a3bb5fc7d68307a43555f98ce15a359

Authored by Anastasia
1 parent a1da4203

change order price

Showing 2 changed files with 17 additions and 2 deletions   Show diff stats
views/order/_form.php
... ... @@ -119,7 +119,7 @@ JS;
119 119 foreach ($model->orderProducts as $index => $orderProduct) {
120 120 $sum += ($orderProduct->count * $orderProduct->price)
121 121 ?>
122   - <div class="row row-order-product">
  122 + <div class="row row-order-product" data-price="<?=$orderProduct->price?>">
123 123 <div class="col-md-4">
124 124 <?php
125 125 echo $form->field($orderProduct, "[$index]variant_id")
... ... @@ -134,7 +134,7 @@ JS;
134 134 <div class="col-md-3">
135 135 <?php
136 136 echo $form->field($orderProduct, "[$index]count")
137   - ->textInput()
  137 + ->textInput(['class' => 'count'])
138 138 ->label(false);
139 139 ?>
140 140 </div>
... ...
web/js/order.js
... ... @@ -2,9 +2,15 @@ $(function() {
2 2 $(document)
3 3 .on('click', '.remove-order-product', function(e) {
4 4 e.preventDefault();
  5 + var current_price = parseInt($(this).parents('.row-order-product').data('price'));
  6 + var number = parseInt($(this).parents('.row-order-product').children('.col-md-3').children('.form-group').children('input').val());
5 7 $(this)
6 8 .parents('.row-order-product')
7 9 .remove();
  10 + var total_price = parseInt($(".sum_all").children('p').text());
  11 + total_price = total_price - (current_price * number);
  12 + console.log(number);
  13 + $(".sum_all").children('p').text(total_price);
8 14 });
9 15 $(document)
10 16 .on('click', '.variant-to-order', function(e) {
... ... @@ -36,6 +42,15 @@ $(function() {
36 42 .trigger('change');
37 43 }
38 44 });
  45 + $(document).on('change', '.count', function() {
  46 + var count_old = parseInt(this.defaultValue);
  47 + var count_new = parseInt(this.value);
  48 + var current_price = parseInt($(this).parents('.row-order-product').data('price'));
  49 + var total_price = parseInt($(".sum_all").children('p').text());
  50 + total_price = total_price - (count_old * current_price) + (count_new * current_price);
  51 + this.defaultValue = this.value;
  52 + $(".sum_all").children('p').text(total_price);
  53 + })
39 54 });
40 55 function showLoader(container) {
41 56 $(container)
... ...