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,7 +119,7 @@ JS;
119 foreach ($model->orderProducts as $index => $orderProduct) { 119 foreach ($model->orderProducts as $index => $orderProduct) {
120 $sum += ($orderProduct->count * $orderProduct->price) 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 <div class="col-md-4"> 123 <div class="col-md-4">
124 <?php 124 <?php
125 echo $form->field($orderProduct, "[$index]variant_id") 125 echo $form->field($orderProduct, "[$index]variant_id")
@@ -134,7 +134,7 @@ JS; @@ -134,7 +134,7 @@ JS;
134 <div class="col-md-3"> 134 <div class="col-md-3">
135 <?php 135 <?php
136 echo $form->field($orderProduct, "[$index]count") 136 echo $form->field($orderProduct, "[$index]count")
137 - ->textInput() 137 + ->textInput(['class' => 'count'])
138 ->label(false); 138 ->label(false);
139 ?> 139 ?>
140 </div> 140 </div>
@@ -2,9 +2,15 @@ $(function() { @@ -2,9 +2,15 @@ $(function() {
2 $(document) 2 $(document)
3 .on('click', '.remove-order-product', function(e) { 3 .on('click', '.remove-order-product', function(e) {
4 e.preventDefault(); 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 $(this) 7 $(this)
6 .parents('.row-order-product') 8 .parents('.row-order-product')
7 .remove(); 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 $(document) 15 $(document)
10 .on('click', '.variant-to-order', function(e) { 16 .on('click', '.variant-to-order', function(e) {
@@ -36,6 +42,15 @@ $(function() { @@ -36,6 +42,15 @@ $(function() {
36 .trigger('change'); 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 function showLoader(container) { 55 function showLoader(container) {
41 $(container) 56 $(container)