Commit a55bed64864b7e247f5622b97d6bd654a23ce287
1 parent
7f07c94f
- order
- basket
Showing
3 changed files
with
13 additions
and
25 deletions
Show diff stats
controllers/OrderController.php
| @@ -315,22 +315,14 @@ | @@ -315,22 +315,14 @@ | ||
| 315 | * @var Variant[] $variants | 315 | * @var Variant[] $variants |
| 316 | */ | 316 | */ |
| 317 | $variants = Variant::find() | 317 | $variants = Variant::find() |
| 318 | - ->joinWith('lang', false) | ||
| 319 | ->joinWith('product.lang', false) | 318 | ->joinWith('product.lang', false) |
| 320 | - ->andWhere( | 319 | + ->where( |
| 321 | [ | 320 | [ |
| 322 | 'like', | 321 | 'like', |
| 323 | 'product_lang.title', | 322 | 'product_lang.title', |
| 324 | $q, | 323 | $q, |
| 325 | ] | 324 | ] |
| 326 | ) | 325 | ) |
| 327 | - ->orWhere( | ||
| 328 | - [ | ||
| 329 | - 'like', | ||
| 330 | - 'variant_lang.title', | ||
| 331 | - $q, | ||
| 332 | - ] | ||
| 333 | - ) | ||
| 334 | ->orWhere([ 'variant.sku' => $q ]) | 326 | ->orWhere([ 'variant.sku' => $q ]) |
| 335 | ->all(); | 327 | ->all(); |
| 336 | foreach ($variants as $variant) { | 328 | foreach ($variants as $variant) { |
views/order/_form.php
| @@ -150,8 +150,8 @@ | @@ -150,8 +150,8 @@ | ||
| 150 | 150 | ||
| 151 | <div id="product-rows" class="col-xs-12"> | 151 | <div id="product-rows" class="col-xs-12"> |
| 152 | <?php | 152 | <?php |
| 153 | + $sum = 0; | ||
| 153 | if (!$model->isNewRecord) { | 154 | if (!$model->isNewRecord) { |
| 154 | - $sum = 0; | ||
| 155 | foreach ($model->orderProducts as $index => $orderProduct) { | 155 | foreach ($model->orderProducts as $index => $orderProduct) { |
| 156 | $sum += ( $orderProduct->count * $orderProduct->price ); | 156 | $sum += ( $orderProduct->count * $orderProduct->price ); |
| 157 | echo $this->render( | 157 | echo $this->render( |
| @@ -171,7 +171,7 @@ | @@ -171,7 +171,7 @@ | ||
| 171 | 171 | ||
| 172 | </div> | 172 | </div> |
| 173 | <?php | 173 | <?php |
| 174 | - echo( " <div class='sum_all col-xs-12'>Итого: <strong>" . $sum . "</strong></div>" ); | 174 | + echo( " <div class='sum_all col-xs-12'>Итого: <strong id='total-sum'>" . $sum . "</strong></div>" ); |
| 175 | ?> | 175 | ?> |
| 176 | </div> | 176 | </div> |
| 177 | </div> | 177 | </div> |
web/js/order.js
| @@ -3,7 +3,8 @@ $(function() { | @@ -3,7 +3,8 @@ $(function() { | ||
| 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')); | 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()); | 6 | + console.log(current_price); |
| 7 | + var number = parseInt($(this).parents('.row-order-product').children('.col-md-2').children('.form-group').children('input').val()); | ||
| 7 | var id = $(this) | 8 | var id = $(this) |
| 8 | .data('id'); | 9 | .data('id'); |
| 9 | var variant = $(this) | 10 | var variant = $(this) |
| @@ -11,14 +12,11 @@ $(function() { | @@ -11,14 +12,11 @@ $(function() { | ||
| 11 | $(this) | 12 | $(this) |
| 12 | .parents('.row-order-product') | 13 | .parents('.row-order-product') |
| 13 | .remove(); | 14 | .remove(); |
| 14 | - var total_price = parseInt($(".sum_all") | ||
| 15 | - .children('p') | ||
| 16 | - .text()); | 15 | + var total_price = parseInt($("#total-sum").text()); |
| 16 | + console.log(total_price); | ||
| 17 | total_price = total_price - (current_price * number); | 17 | total_price = total_price - (current_price * number); |
| 18 | console.log(number); | 18 | console.log(number); |
| 19 | - $(".sum_all") | ||
| 20 | - .children('p') | ||
| 21 | - .text(total_price); | 19 | + $("#total-sum").text(total_price); |
| 22 | }); | 20 | }); |
| 23 | $('#count-to-order').keypress(function(e) { | 21 | $('#count-to-order').keypress(function(e) { |
| 24 | if (!(e.which==8 ||(e.which>47 && e.which<58))) return false; | 22 | if (!(e.which==8 ||(e.which>47 && e.which<58))) return false; |
| @@ -50,11 +48,9 @@ $(function() { | @@ -50,11 +48,9 @@ $(function() { | ||
| 50 | order: order | 48 | order: order |
| 51 | }, function(data) { | 49 | }, function(data) { |
| 52 | if (data.success) { | 50 | if (data.success) { |
| 53 | - var sum = $(".sum_all") | ||
| 54 | - .children('p') | ||
| 55 | - .text(); | ||
| 56 | - $(".sum_all") | ||
| 57 | - .children('p') | 51 | + var sum = $('#total-sum').text(); |
| 52 | + console.log(sum); | ||
| 53 | + $('#total-sum') | ||
| 58 | .html(parseInt(sum) + parseInt(data.price)); | 54 | .html(parseInt(sum) + parseInt(data.price)); |
| 59 | $('#product-rows') | 55 | $('#product-rows') |
| 60 | .append(data.row); | 56 | .append(data.row); |
| @@ -69,10 +65,10 @@ $(function() { | @@ -69,10 +65,10 @@ $(function() { | ||
| 69 | console.log(count_old); | 65 | console.log(count_old); |
| 70 | var count_new = parseInt(this.value); | 66 | var count_new = parseInt(this.value); |
| 71 | var current_price = parseInt($(this).parents('.row-order-product').data('price')); | 67 | var current_price = parseInt($(this).parents('.row-order-product').data('price')); |
| 72 | - var total_price = parseInt($(".sum_all").children('p').text()); | 68 | + var total_price = parseInt($("#total-sum").text()); |
| 73 | total_price = total_price - (count_old * current_price) + (count_new * current_price); | 69 | total_price = total_price - (count_old * current_price) + (count_new * current_price); |
| 74 | this.defaultValue = this.value; | 70 | this.defaultValue = this.value; |
| 75 | - $(".sum_all").children('p').text(total_price); | 71 | + $("#total-sum").text(total_price); |
| 76 | }) | 72 | }) |
| 77 | }); | 73 | }); |
| 78 | function showLoader(container) { | 74 | function showLoader(container) { |