Commit 7913794001c19d701d9af8c1eddcb2c20ab7cc29

Authored by Volodymyr
1 parent ccc6baf5

fix product modal

common/models/ProductLang.php
@@ -57,7 +57,7 @@ class ProductLang extends ActiveRecord @@ -57,7 +57,7 @@ class ProductLang extends ActiveRecord
57 'targetAttribute' => [ 'language_id' => 'id' ], 57 'targetAttribute' => [ 'language_id' => 'id' ],
58 ], 58 ],
59 [ 59 [
60 - [ 'tile_id' ], 60 + [ 'product_id' ],
61 'exist', 61 'exist',
62 'skipOnError' => true, 62 'skipOnError' => true,
63 'targetClass' => Product::className(), 63 'targetClass' => Product::className(),
frontend/controllers/SiteController.php
@@ -102,8 +102,8 @@ @@ -102,8 +102,8 @@
102 ->orderBy('id') 102 ->orderBy('id')
103 ->limit(4) 103 ->limit(4)
104 ->all(); 104 ->all();
105 - $productsCompany = Product::find()->where(['!=','type',Product::TYPE_PRIVATE])->all();  
106 - $productsPrivate = Product::find()->where(['!=','type',Product::TYPE_COMPANY])->all(); 105 + $productsCompany = Product::find()->with(['lang', 'image'])->where(['!=','type',Product::TYPE_PRIVATE])->all();
  106 + $productsPrivate = Product::find()->with(['lang', 'image'])->where(['!=','type',Product::TYPE_COMPANY])->all();
107 return $this->render( 107 return $this->render(
108 'index', 108 'index',
109 [ 109 [
frontend/views/site/_product.php
  1 +<?php
  2 +
  3 +/**
  4 + * @var Product $product
  5 + */
  6 +
  7 +use common\models\Product;
  8 +
  9 +?>
1 <div class="col-xs-6 col-sm-3 index-solution-slider__col"> 10 <div class="col-xs-6 col-sm-3 index-solution-slider__col">
2 <div class="index-solution-slider__item"> 11 <div class="index-solution-slider__item">
3 - <a href="#" class="index-solution-slider__item_img"> 12 + <a href="#" data-toggle="modal" data-target="#cardProduct" data-image="<?= $product->image->getUrl() ?>" data-price="<?= $product->price ?>" data-sku="<?= $product->sku ?>" class="index-solution-slider__item_img">
4 <!--обрезать по высоте в 211px--> 13 <!--обрезать по высоте в 211px-->
5 - <img src="/img/new-index/slider-items/slider-item-1.jpg" alt=""> 14 + <?= $product->image->getImg([]) ?>
6 </a> 15 </a>
7 - <a href="#" class="index-solution-slider__item_link">Промышленная солнечная электростанция 2 МВт  
8 - "Под ключ"</a>  
9 - <div class="index-solution-slider__item_price">1740000.00 $</div> 16 + <a href="#" data-toggle="modal" data-target="#cardProduct" data-image="<?= $product->image->getUrl() ?>" data-price="<?= $product->price ?>" data-sku="<?= $product->sku ?>" class="index-solution-slider__item_link">
  17 + <?= $product->lang->title ?>
  18 + </a>
  19 + <div class="index-solution-slider__item_price"><?= $product->price ?> $</div>
10 </div> 20 </div>
11 </div> 21 </div>
12 \ No newline at end of file 22 \ No newline at end of file
frontend/views/site/index.php
@@ -550,8 +550,6 @@ $coordinates[&#39;lon&#39;] = empty($settings-&gt;lon) ? 0 : $settings-&gt;lon; @@ -550,8 +550,6 @@ $coordinates[&#39;lon&#39;] = empty($settings-&gt;lon) ? 0 : $settings-&gt;lon;
550 width="100%" height="380" style="border:0;" allowfullscreen="" loading="lazy"></iframe> 550 width="100%" height="380" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
551 </section> 551 </section>
552 </div> 552 </div>
553 -<a href="#" class="animation-hover" data-boo="fffff" data-title="hhh" data-toggle="modal" data-target="#cardProduct">  
554 - Получить консультацию </a>  
555 <!-- Modal --> 553 <!-- Modal -->
556 <div class="modal fade" id="cardProduct" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> 554 <div class="modal fade" id="cardProduct" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
557 <div class="modal-dialog modal-lg"> 555 <div class="modal-dialog modal-lg">
frontend/web/js/product.js
1 var phoneInput = document.querySelector('#cardProduct [type="tel"]'); 1 var phoneInput = document.querySelector('#cardProduct [type="tel"]');
2 var counter = document.querySelector('#cardProduct .product-counter__input'); 2 var counter = document.querySelector('#cardProduct .product-counter__input');
3 - 3 +var price = 0;
4 if (phoneInput) { 4 if (phoneInput) {
5 phoneInput.addEventListener('input', phoneHandleInput); 5 phoneInput.addEventListener('input', phoneHandleInput);
6 } 6 }
7 $('#cardProduct').on('show.bs.modal', function (e) { 7 $('#cardProduct').on('show.bs.modal', function (e) {
8 - var button = $(e.relatedTarget)  
9 - console.log(button.data('boo')); 8 + var button = $(e.relatedTarget);
  9 + price = button.data('price');
  10 + $('#cardProduct .product-counter__value').data('price', price);
  11 + var itemPrice = counter.parentElement.querySelector('.product-counter__value');
  12 + itemPrice.innerHTML = `${price} ${itemPrice.dataset.currency}`;
  13 + counter.querySelector('input').value = 1;
10 }) 14 })
11 -  
12 -if (counter) {  
13 - counterFunc(counter); 15 +if(counter){
  16 + counterFunc(counter);
14 } 17 }
15 18
  19 +
16 function phoneHandleInput(e) { 20 function phoneHandleInput(e) {
17 e.target.value = phoneMasks(e.target.value); 21 e.target.value = phoneMasks(e.target.value);
18 } 22 }
@@ -27,8 +31,8 @@ function phoneMasks(phone) { @@ -27,8 +31,8 @@ function phoneMasks(phone) {
27 } 31 }
28 32
29 function counterFunc(counter) { 33 function counterFunc(counter) {
30 - let itemPrice = counter.parentElement.querySelector('.product-counter__value');  
31 - itemPrice.innerHTML = `${itemPrice.dataset.price} ${itemPrice.dataset.currency}`; 34 + var itemPrice = counter.parentElement.querySelector('.product-counter__value');
  35 + itemPrice.innerHTML = `${price} ${itemPrice.dataset.currency}`;
32 36
33 counter.querySelector('input').value = 1; 37 counter.querySelector('input').value = 1;
34 counter.addEventListener('input', counterHandleInput); 38 counter.addEventListener('input', counterHandleInput);
@@ -42,7 +46,7 @@ function counterFunc(counter) { @@ -42,7 +46,7 @@ function counterFunc(counter) {
42 } 46 }
43 47
44 function counterHandleChange(e) { 48 function counterHandleChange(e) {
45 - const value = e.target.value.replace(/\D/g, ''); 49 + var value = e.target.value.replace(/\D/g, '');
46 if (value == 0) { 50 if (value == 0) {
47 e.target.value = 1; 51 e.target.value = 1;
48 } 52 }
@@ -51,14 +55,16 @@ function counterFunc(counter) { @@ -51,14 +55,16 @@ function counterFunc(counter) {
51 55
52 function increment(e) { 56 function increment(e) {
53 e.preventDefault(); 57 e.preventDefault();
54 - const value = Number(counter.querySelector('input').value); 58 + var value = Number(counter.querySelector('input').value);
  59 + //console.log(value);
55 counter.querySelector('input').value = value + 1; 60 counter.querySelector('input').value = value + 1;
  61 + console.log(value);
56 updateSummary(); 62 updateSummary();
57 } 63 }
58 64
59 function decrement(e) { 65 function decrement(e) {
60 e.preventDefault(); 66 e.preventDefault();
61 - const value = Number(counter.querySelector('input').value); 67 + var value = Number(counter.querySelector('input').value);
62 if (value > 1) { 68 if (value > 1) {
63 counter.querySelector('input').value = value - 1; 69 counter.querySelector('input').value = value - 1;
64 updateSummary(); 70 updateSummary();
@@ -66,11 +72,11 @@ function counterFunc(counter) { @@ -66,11 +72,11 @@ function counterFunc(counter) {
66 } 72 }
67 73
68 function updateSummary() { 74 function updateSummary() {
69 - const amount = counter.querySelector('input').value; 75 + var amount = counter.querySelector('input').value;
70 if (amount >= 1) { 76 if (amount >= 1) {
71 - const oldSum = Number(itemPrice.dataset.price) * 10;  
72 - const newSum = String(oldSum * amount);  
73 - itemPrice.innerHTML = `${newSum.slice(0, -2)}.${newSum.slice(-2)} ${itemPrice.dataset.currency}`; 77 + var oldSum = Number(price);
  78 + var newSum = String(oldSum * amount);
  79 + itemPrice.innerHTML = `${newSum} ${itemPrice.dataset.currency}`;
74 } 80 }
75 } 81 }
76 } 82 }
77 \ No newline at end of file 83 \ No newline at end of file