Commit a55bed64864b7e247f5622b97d6bd654a23ce287

Authored by Anastasia
1 parent 7f07c94f

- order

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