Commit 8b638e12448ced41ce4cf51119db2360f464cdb0
1 parent
543a6adb
sum in order
Showing
4 changed files
with
15 additions
and
9 deletions
Show diff stats
controllers/OrderController.php
views/order/_form.php
@@ -30,9 +30,6 @@ | @@ -30,9 +30,6 @@ | ||
30 | <?= $form->field($model, 'name') | 30 | <?= $form->field($model, 'name') |
31 | ->textInput([ 'maxlength' => true ]) ?> | 31 | ->textInput([ 'maxlength' => true ]) ?> |
32 | 32 | ||
33 | - <?= $form->field($model, 'secondname') | ||
34 | - ->textInput([ 'maxlength' => true ]) ?> | ||
35 | - | ||
36 | <?= $form->field($model, 'phone') | 33 | <?= $form->field($model, 'phone') |
37 | ->textInput([ 'maxlength' => true ]) ?> | 34 | ->textInput([ 'maxlength' => true ]) ?> |
38 | 35 | ||
@@ -142,7 +139,9 @@ | @@ -142,7 +139,9 @@ | ||
142 | <div id="product-rows"> | 139 | <div id="product-rows"> |
143 | <?php | 140 | <?php |
144 | if (!$model->isNewRecord) { | 141 | if (!$model->isNewRecord) { |
142 | + $sum = 0; | ||
145 | foreach ($model->orderProducts as $index => $orderProduct) { | 143 | foreach ($model->orderProducts as $index => $orderProduct) { |
144 | + $sum += ( $orderProduct->count * $orderProduct->price ); | ||
146 | echo $this->render( | 145 | echo $this->render( |
147 | '_order_product', | 146 | '_order_product', |
148 | [ | 147 | [ |
@@ -154,9 +153,14 @@ | @@ -154,9 +153,14 @@ | ||
154 | ] | 153 | ] |
155 | ); | 154 | ); |
156 | } | 155 | } |
156 | + | ||
157 | } | 157 | } |
158 | ?> | 158 | ?> |
159 | + | ||
159 | </div> | 160 | </div> |
161 | + <?php if (!$model->isNewRecord) { | ||
162 | + echo( " <div class='sum_all'>Всего <p>" . $sum . "</p></div>" ); | ||
163 | + } ?> | ||
160 | </div> | 164 | </div> |
161 | </div> | 165 | </div> |
162 | 166 |
views/order/_order_product.php
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | 17 | ||
18 | ?> | 18 | ?> |
19 | 19 | ||
20 | -<div class="row row-order-product"> | 20 | +<div class="row row-order-product" data-price="<?= $price ?>"> |
21 | <div class="col-md-4"> | 21 | <div class="col-md-4"> |
22 | <?php | 22 | <?php |
23 | echo $form->field($orderProduct, "[$index]variant_id") | 23 | echo $form->field($orderProduct, "[$index]variant_id") |
@@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
32 | <div class="col-md-3"> | 32 | <div class="col-md-3"> |
33 | <?php | 33 | <?php |
34 | echo $form->field($orderProduct, "[$index]count") | 34 | echo $form->field($orderProduct, "[$index]count") |
35 | - ->textInput() | 35 | + ->textInput([ 'class' => 'count' ]) |
36 | ->label(false); | 36 | ->label(false); |
37 | ?> | 37 | ?> |
38 | </div> | 38 | </div> |
web/js/order.js
@@ -29,21 +29,21 @@ $(function() { | @@ -29,21 +29,21 @@ $(function() { | ||
29 | var order = $(this) | 29 | var order = $(this) |
30 | .data('id'); | 30 | .data('id'); |
31 | if (id.val() && count.val()) { | 31 | if (id.val() && count.val()) { |
32 | - var selector = '#order-product-pjax'; | ||
33 | $.post('/admin/order/add-to-order', { | 32 | $.post('/admin/order/add-to-order', { |
34 | id: id.val(), | 33 | id: id.val(), |
35 | count: count.val(), | 34 | count: count.val(), |
36 | order: order | 35 | order: order |
37 | }, function(data) { | 36 | }, function(data) { |
38 | if (data.success) { | 37 | if (data.success) { |
39 | - $('#product-rows') | ||
40 | - .append(data.row); | ||
41 | var sum = $(".sum_all") | 38 | var sum = $(".sum_all") |
42 | .children('p') | 39 | .children('p') |
43 | .text(); | 40 | .text(); |
44 | $(".sum_all") | 41 | $(".sum_all") |
45 | .children('p') | 42 | .children('p') |
46 | - .html(parseInt(sum) + parseInt(data)); | 43 | + .html(parseInt(sum) + parseInt(data.price)); |
44 | + $('#product-rows') | ||
45 | + .append(data.row); | ||
46 | + | ||
47 | } | 47 | } |
48 | 48 | ||
49 | }); | 49 | }); |
@@ -51,6 +51,7 @@ $(function() { | @@ -51,6 +51,7 @@ $(function() { | ||
51 | }); | 51 | }); |
52 | $(document).on('change', '.count', function() { | 52 | $(document).on('change', '.count', function() { |
53 | var count_old = parseInt(this.defaultValue); | 53 | var count_old = parseInt(this.defaultValue); |
54 | + console.log(count_old); | ||
54 | var count_new = parseInt(this.value); | 55 | var count_new = parseInt(this.value); |
55 | var current_price = parseInt($(this).parents('.row-order-product').data('price')); | 56 | var current_price = parseInt($(this).parents('.row-order-product').data('price')); |
56 | var total_price = parseInt($(".sum_all").children('p').text()); | 57 | var total_price = parseInt($(".sum_all").children('p').text()); |