Commit 01905ec61675d700172288819755ea2317551d85
1 parent
aa5c63f4
Filter fixing
Showing
6 changed files
with
49 additions
and
30 deletions
Show diff stats
common/modules/product/helpers/ProductHelper.php
... | ... | @@ -292,4 +292,12 @@ |
292 | 292 | |
293 | 293 | return $query; |
294 | 294 | } |
295 | + | |
296 | + public static function addLastCategory($category_id) { | |
297 | + \Yii::$app->session->set('last_category_id', $category_id); | |
298 | + } | |
299 | + | |
300 | + public static function getLastCategory() { | |
301 | + return \Yii::$app->session->get('last_category_id'); | |
302 | + } | |
295 | 303 | } |
296 | 304 | \ No newline at end of file | ... | ... |
common/modules/product/models/Product.php
... | ... | @@ -11,6 +11,7 @@ use common\modules\rubrication\models\TaxGroup; |
11 | 11 | use common\modules\rubrication\models\TaxOption; |
12 | 12 | use Yii; |
13 | 13 | use common\modules\relation\relationBehavior; |
14 | +use yii\db\ActiveQuery; | |
14 | 15 | use yii\db\ActiveRecord; |
15 | 16 | use yii\helpers\ArrayHelper; |
16 | 17 | |
... | ... | @@ -240,7 +241,10 @@ class Product extends \yii\db\ActiveRecord |
240 | 241 | public function getVariantsWithFilters(){ |
241 | 242 | return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters'); |
242 | 243 | } |
243 | - | |
244 | + | |
245 | + /** | |
246 | + * @return ActiveQuery | |
247 | + */ | |
244 | 248 | public function getCategory() { |
245 | 249 | return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); |
246 | 250 | } |
... | ... | @@ -263,12 +267,12 @@ class Product extends \yii\db\ActiveRecord |
263 | 267 | return $groups; |
264 | 268 | } |
265 | 269 | |
266 | - public function getActiveProperties() { | |
270 | + public function getActiveProperties($category_id) { | |
267 | 271 | $groups = $options = []; |
268 | 272 | foreach ($this->options as $option) { |
269 | 273 | $options[$option->tax_group_id][] = $option; |
270 | 274 | } |
271 | - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options), 'display' => TRUE])->all() as $group) { | |
275 | + foreach (TaxGroup::find()->joinWith('categories')->where(['tax_group.tax_group_id' => array_keys($options), 'tax_group.display' => TRUE, 'category.category_id' => $category_id])->all() as $group) { | |
272 | 276 | if (!empty($options[$group->tax_group_id])) { |
273 | 277 | $group->_options = $options[$group->tax_group_id]; |
274 | 278 | $groups[] = $group; |
... | ... | @@ -432,6 +436,6 @@ class Product extends \yii\db\ActiveRecord |
432 | 436 | public function getTaxGroupsByLevel($level) |
433 | 437 | { |
434 | 438 | $categories = ArrayHelper::getColumn($this->categories, 'category_id'); |
435 | - return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->where(['relation.entity2_id' => $categories])->where(['level' => $level]); | |
439 | + return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->andWhere(['relation.entity2_id' => $categories])->andWhere(['level' => $level]); | |
436 | 440 | } |
437 | 441 | } | ... | ... |
common/modules/rubrication/models/TaxGroup.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace common\modules\rubrication\models; |
4 | 4 | |
5 | +use common\modules\product\models\Category; | |
5 | 6 | use common\modules\relation\relationBehavior; |
6 | 7 | use Yii; |
7 | 8 | |
... | ... | @@ -99,6 +100,12 @@ class TaxGroup extends \yii\db\ActiveRecord |
99 | 100 | return $this->hasMany(TaxGroupToGroup::className(), ['tax_group1_id' => 'tax_group_id'])->inverseOf('taxGroup1'); |
100 | 101 | } |
101 | 102 | |
103 | + public function getCategories() | |
104 | + { | |
105 | + return $this->hasMany(Category::className(), ['category_id' => 'entity2_id']) | |
106 | + ->viaTable('relation', ['entity1_id' => 'tax_group_id']); | |
107 | + } | |
108 | + | |
102 | 109 | /** |
103 | 110 | * @return \yii\db\ActiveQuery |
104 | 111 | */ | ... | ... |
frontend/controllers/CatalogController.php
... | ... | @@ -45,6 +45,8 @@ |
45 | 45 | return $this->render('catalog'); |
46 | 46 | } |
47 | 47 | |
48 | + ProductHelper::addLastCategory($category->category_id); | |
49 | + | |
48 | 50 | $params = [ ]; |
49 | 51 | |
50 | 52 | $optionsList = ArrayHelper::getColumn(TaxGroup::find() |
... | ... | @@ -172,9 +174,18 @@ |
172 | 174 | |
173 | 175 | ProductHelper::addLastProsucts($product->product_id); |
174 | 176 | |
177 | + $category = null; | |
178 | + $last_category_id = ProductHelper::getLastCategory(); | |
179 | + if(!empty($last_category_id)) { | |
180 | + $category = $product->getCategory()->andWhere(['category_id' => $last_category_id])->one(); | |
181 | + } | |
182 | + if(empty($category)) { | |
183 | + $category = $product->category; | |
184 | + } | |
185 | + | |
175 | 186 | return $this->render('product', [ |
176 | 187 | 'product' => $product, |
177 | - 'category' => $product->category, | |
188 | + 'category' => $category, | |
178 | 189 | ]); |
179 | 190 | } |
180 | 191 | ... | ... |
frontend/views/catalog/product.php
1 | 1 | <?php |
2 | + /** | |
3 | + * @var Category $category | |
4 | + */ | |
2 | 5 | // use common\modules\comment\models\Comment; |
3 | 6 | // use common\modules\comment\models\Rating; |
4 | 7 | // use common\modules\comment\widgets\CommentWidget; |
5 | 8 | use common\modules\comment\widgets\CommentWidget; |
6 | - use kartik\rating\StarRating; | |
7 | - use yii\helpers\Html; | |
8 | - use yii\widgets\ActiveForm; | |
9 | - use yii\widgets\Breadcrumbs; | |
9 | + use common\modules\product\models\Category; | |
10 | 10 | use yii\web\View; |
11 | 11 | use yii\helpers\Url; |
12 | 12 | use frontend\widgets\Seo; |
13 | 13 | |
14 | - $this->params[ 'seo' ][ 'key' ] = $product->category->categoryName->value; | |
14 | + $this->params[ 'seo' ][ 'key' ] = $category->categoryName->value; | |
15 | 15 | $this->params[ 'seo' ][ 'fields' ][ 'name' ] = $product->fullname; |
16 | 16 | $this->params[ 'seo' ][ 'h1' ] = !empty( Seo::widget([ 'row' => 'h1' ]) ) ? Seo::widget([ 'row' => 'h1' ]) : $product->fullname; |
17 | 17 | |
... | ... | @@ -30,10 +30,10 @@ |
30 | 30 | 'url' => [ 'catalog/category' ], |
31 | 31 | ]; |
32 | 32 | $this->params[ 'breadcrumbs' ][] = [ |
33 | - 'label' => $product->category->categoryName->value, | |
33 | + 'label' => $category->categoryName->value, | |
34 | 34 | 'url' => [ |
35 | 35 | 'catalog/category', |
36 | - 'category' => $product->category, | |
36 | + 'category' => $category, | |
37 | 37 | ], |
38 | 38 | ]; |
39 | 39 | $this->params[ 'breadcrumbs' ][] = $product->fullname . ' #' . $product->enabledVariants[ 0 ]->sku; |
... | ... | @@ -126,8 +126,8 @@ |
126 | 126 | data-imageoriginal="<?= $variant->imageUrl ?>" |
127 | 127 | title="<?= $product->fullname ?>"> |
128 | 128 | <?= \common\components\artboximage\ArtboxImageHelper::getImage($variant->imageUrl, 'product_variant', [ |
129 | - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, | |
130 | - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, | |
129 | + 'alt' => $category->categoryName->value . ' ' . $product->fullname, | |
130 | + 'title' => $category->categoryName->value . ' ' . $product->fullname, | |
131 | 131 | ]) ?> |
132 | 132 | </a> |
133 | 133 | </li> |
... | ... | @@ -228,7 +228,7 @@ |
228 | 228 | <li><a href="#">Характеристики</a> |
229 | 229 | <div class="info"> |
230 | 230 | <p>Бренд: <?= $product->brand->name ?></p> |
231 | - <?php foreach($product->activeProperties as $group): ?> | |
231 | + <?php foreach($product->getActiveProperties($category->category_id) as $group): ?> | |
232 | 232 | <p><?= $group->name ?> <?php foreach($group->_options as $option) : ?> <?= $option->ValueRenderHTML ?><?php endforeach ?></p> |
233 | 233 | <?php endforeach; ?> |
234 | 234 | </div> |
... | ... | @@ -262,8 +262,8 @@ |
262 | 262 | <center> |
263 | 263 | <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[ 0 ]->imageUrl, 'product_view', [ |
264 | 264 | 'id' => 'pic', |
265 | - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, | |
266 | - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, | |
265 | + 'alt' => $category->categoryName->value . ' ' . $product->fullname, | |
266 | + 'title' => $category->categoryName->value . ' ' . $product->fullname, | |
267 | 267 | ]) ?></a> |
268 | 268 | </center> |
269 | 269 | </div> |
... | ... | @@ -271,8 +271,8 @@ |
271 | 271 | <?php foreach($product->images as $image): ?> |
272 | 272 | <li><a href="<?= $image->imageUrl ?>" rel="shadowbox[gal]"> |
273 | 273 | <?= \common\components\artboximage\ArtboxImageHelper::getImage($image->imageUrl, 'product_trumb2', [ |
274 | - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, | |
275 | - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, | |
274 | + 'alt' => $category->categoryName->value . ' ' . $product->fullname, | |
275 | + 'title' => $category->categoryName->value . ' ' . $product->fullname, | |
276 | 276 | ]) ?> |
277 | 277 | </a></li> |
278 | 278 | <?php endforeach; ?> | ... | ... |
frontend/views/search/index.php
... | ... | @@ -21,17 +21,6 @@ $this->params['breadcrumbs'][] = ['label' => 'Поиск', 'url' => ['catalog/ca |
21 | 21 | $this->params['seo']['meta']= 'noindex,follow'; |
22 | 22 | ?> |
23 | 23 | |
24 | - | |
25 | -<nav class="bread-crumbs"> | |
26 | - <?= \yii\widgets\Breadcrumbs::widget ([ | |
27 | - 'links' => $this->params['breadcrumbs'], | |
28 | - ]) | |
29 | - ?> | |
30 | - | |
31 | - | |
32 | - <div class="both"></div> | |
33 | -</nav> | |
34 | - | |
35 | 24 | <div class="loyout"> |
36 | 25 | <?php if(!empty($categories)) :?> |
37 | 26 | <div class="leftbar"> | ... | ... |