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