Commit 1e55b4b87ef6db37cb7d3a89bc3c35653d89a625
1 parent
1d90183c
-
Showing
6 changed files
with
30 additions
and
10 deletions
Show diff stats
common/modules/product/models/Product.php
... | ... | @@ -136,7 +136,7 @@ class Product extends \yii\db\ActiveRecord |
136 | 136 | */ |
137 | 137 | public function getImages() |
138 | 138 | { |
139 | - return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id']); | |
139 | + return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id'])->where(['product_variant_id' => null]); | |
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
... | ... | @@ -144,12 +144,14 @@ class Product extends \yii\db\ActiveRecord |
144 | 144 | */ |
145 | 145 | public function getVariant() |
146 | 146 | { |
147 | +// return ProductVariant::find()->filterWhere([ProductVariant::tableName() .'.product_id' => Product::tableName() .'.product_id'])->where('>', ProductVariant::tableName() .'.stock', 0); | |
147 | 148 | return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); |
148 | 149 | } |
149 | 150 | |
150 | 151 | public function getVariantPrice() { |
151 | 152 | return $this->variant->price; |
152 | 153 | } |
154 | + | |
153 | 155 | /** |
154 | 156 | * @return \yii\db\ActiveQuery |
155 | 157 | */ |
... | ... | @@ -158,6 +160,18 @@ class Product extends \yii\db\ActiveRecord |
158 | 160 | return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']); |
159 | 161 | } |
160 | 162 | |
163 | + public function getEnabledVariants() | |
164 | + { | |
165 | + /*$result = []; | |
166 | + foreach ($this->variants as $variant) { | |
167 | + if (is_null($variant->stock) || $variant->stock > 0) { | |
168 | + $result[] = $variant; | |
169 | + } | |
170 | + } | |
171 | + return $result;*/ | |
172 | + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->where(['!=', ProductVariant::tableName() .'.stock', 0]); | |
173 | + } | |
174 | + | |
161 | 175 | public function setVariants($variants) { |
162 | 176 | $this->_variants = $variants; |
163 | 177 | } |
... | ... | @@ -201,6 +215,12 @@ class Product extends \yii\db\ActiveRecord |
201 | 215 | return new ProductQuery(get_called_class()); |
202 | 216 | } |
203 | 217 | |
218 | + public function getQuantity() { | |
219 | + return ProductStock::find() | |
220 | + ->where(['product_id' => $this->product_id]) | |
221 | + ->sum('quantity'); | |
222 | + } | |
223 | + | |
204 | 224 | public function afterSave($insert, $changedAttributes) |
205 | 225 | { |
206 | 226 | parent::afterSave($insert, $changedAttributes); | ... | ... |
common/modules/product/models/ProductVariant.php
... | ... | @@ -108,12 +108,14 @@ class ProductVariant extends \yii\db\ActiveRecord |
108 | 108 | return $this->hasOne(Product::className(), ['product_id' => 'product_id']); |
109 | 109 | } |
110 | 110 | |
111 | + public function getProductStock() { | |
112 | + return $this->hasMany(ProductStock::className(), ['product_variant_id' => 'product_variant_id']); | |
113 | + } | |
114 | + | |
111 | 115 | public function getQuantity() { |
112 | 116 | return ProductStock::find() |
113 | 117 | ->where(['product_variant_id' => $this->product_variant_id]) |
114 | 118 | ->sum('quantity'); |
115 | -// return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_id' => 'product_id'])->sum(ProductStock::tableName() .'.quantity') > 0; | |
116 | -// return $this->stock !== 0; | |
117 | 119 | } |
118 | 120 | |
119 | 121 | public function getStock_caption() { | ... | ... |
frontend/views/catalog/catalog.php
... | ... | @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = ['label' => 'Каталог']; |
17 | 17 | <div class="loyout"> |
18 | 18 | <div class="content"> |
19 | 19 | <h1>Каталог</h1> |
20 | - <?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [124,125,126,127,128]])?> | |
20 | + <?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [136,137,138,139,140]])?> | |
21 | 21 | </div> |
22 | 22 | <div class="both"></div> |
23 | 23 | ... | ... |
frontend/views/catalog/product.php
... | ... | @@ -97,7 +97,7 @@ $this->registerJs (" |
97 | 97 | <div class="begin">Цветовые решения</div> |
98 | 98 | <ul class="product_mod"> |
99 | 99 | <?php foreach ($product->variants as $variant): ?> |
100 | - <?php if ($variant->quantity > 0) continue;?> | |
100 | + <?php if ($variant->quantity == 0) continue;?> | |
101 | 101 | <li> |
102 | 102 | <a id='m<?= $variant->product_variant_id ?>' href="#<?=$variant->product_variant_id ?>" |
103 | 103 | data-cost="<?= $variant->price ?>" |
... | ... | @@ -107,9 +107,6 @@ $this->registerJs (" |
107 | 107 | data-imageoriginal="<?= $variant->imageUrl ?>" |
108 | 108 | title="<?= $product->fullname ?>"> |
109 | 109 | <?= \common\components\artboximage\ArtboxImageHelper::getImage($variant->imageUrl, 'product_variant')?> |
110 | - <?php | |
111 | - var_dump($variant->quantity); | |
112 | - ?> | |
113 | 110 | </a> |
114 | 111 | </li> |
115 | 112 | <?php endforeach; ?> | ... | ... |
frontend/views/catalog/product_item.php
... | ... | @@ -54,7 +54,8 @@ use yii\helpers\Url; |
54 | 54 | |
55 | 55 | <div class="mycarousel"> |
56 | 56 | <ul class="jcarousel jcarousel-skin-tango"> |
57 | - <?php foreach ($product->variants as $variant) : ?> | |
57 | + <?php foreach ($product->enabledVariants as $variant) : ?> | |
58 | + <?php if ($variant->quantity == 0) continue;?> | |
58 | 59 | <?php if (!empty($variant->image)) :?> |
59 | 60 | <li> |
60 | 61 | <a href="<?= Url::to([ | ... | ... |
frontend/views/site/index.php
... | ... | @@ -30,7 +30,7 @@ echo '<div class="home_banner_up">'; |
30 | 30 | echo '</div>' |
31 | 31 | ?> |
32 | 32 | |
33 | -<?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [124,125,126,127,128]])?> | |
33 | +<?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [136,137,138,139,140]])?> | |
34 | 34 | |
35 | 35 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'promo'])?> |
36 | 36 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'new'])?> | ... | ... |