Commit 01905ec61675d700172288819755ea2317551d85

Authored by Yarik
1 parent aa5c63f4

Filter fixing

common/modules/product/helpers/ProductHelper.php
@@ -292,4 +292,12 @@ @@ -292,4 +292,12 @@
292 292
293 return $query; 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 \ No newline at end of file 304 \ No newline at end of file
common/modules/product/models/Product.php
@@ -11,6 +11,7 @@ use common\modules\rubrication\models\TaxGroup; @@ -11,6 +11,7 @@ use common\modules\rubrication\models\TaxGroup;
11 use common\modules\rubrication\models\TaxOption; 11 use common\modules\rubrication\models\TaxOption;
12 use Yii; 12 use Yii;
13 use common\modules\relation\relationBehavior; 13 use common\modules\relation\relationBehavior;
  14 +use yii\db\ActiveQuery;
14 use yii\db\ActiveRecord; 15 use yii\db\ActiveRecord;
15 use yii\helpers\ArrayHelper; 16 use yii\helpers\ArrayHelper;
16 17
@@ -240,7 +241,10 @@ class Product extends \yii\db\ActiveRecord @@ -240,7 +241,10 @@ class Product extends \yii\db\ActiveRecord
240 public function getVariantsWithFilters(){ 241 public function getVariantsWithFilters(){
241 return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters'); 242 return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters');
242 } 243 }
243 - 244 +
  245 + /**
  246 + * @return ActiveQuery
  247 + */
244 public function getCategory() { 248 public function getCategory() {
245 return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); 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,12 +267,12 @@ class Product extends \yii\db\ActiveRecord
263 return $groups; 267 return $groups;
264 } 268 }
265 269
266 - public function getActiveProperties() { 270 + public function getActiveProperties($category_id) {
267 $groups = $options = []; 271 $groups = $options = [];
268 foreach ($this->options as $option) { 272 foreach ($this->options as $option) {
269 $options[$option->tax_group_id][] = $option; 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 if (!empty($options[$group->tax_group_id])) { 276 if (!empty($options[$group->tax_group_id])) {
273 $group->_options = $options[$group->tax_group_id]; 277 $group->_options = $options[$group->tax_group_id];
274 $groups[] = $group; 278 $groups[] = $group;
@@ -432,6 +436,6 @@ class Product extends \yii\db\ActiveRecord @@ -432,6 +436,6 @@ class Product extends \yii\db\ActiveRecord
432 public function getTaxGroupsByLevel($level) 436 public function getTaxGroupsByLevel($level)
433 { 437 {
434 $categories = ArrayHelper::getColumn($this->categories, 'category_id'); 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,6 +2,7 @@
2 2
3 namespace common\modules\rubrication\models; 3 namespace common\modules\rubrication\models;
4 4
  5 +use common\modules\product\models\Category;
5 use common\modules\relation\relationBehavior; 6 use common\modules\relation\relationBehavior;
6 use Yii; 7 use Yii;
7 8
@@ -99,6 +100,12 @@ class TaxGroup extends \yii\db\ActiveRecord @@ -99,6 +100,12 @@ class TaxGroup extends \yii\db\ActiveRecord
99 return $this->hasMany(TaxGroupToGroup::className(), ['tax_group1_id' => 'tax_group_id'])->inverseOf('taxGroup1'); 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 * @return \yii\db\ActiveQuery 110 * @return \yii\db\ActiveQuery
104 */ 111 */
frontend/controllers/CatalogController.php
@@ -45,6 +45,8 @@ @@ -45,6 +45,8 @@
45 return $this->render('catalog'); 45 return $this->render('catalog');
46 } 46 }
47 47
  48 + ProductHelper::addLastCategory($category->category_id);
  49 +
48 $params = [ ]; 50 $params = [ ];
49 51
50 $optionsList = ArrayHelper::getColumn(TaxGroup::find() 52 $optionsList = ArrayHelper::getColumn(TaxGroup::find()
@@ -172,9 +174,18 @@ @@ -172,9 +174,18 @@
172 174
173 ProductHelper::addLastProsucts($product->product_id); 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 return $this->render('product', [ 186 return $this->render('product', [
176 'product' => $product, 187 'product' => $product,
177 - 'category' => $product->category, 188 + 'category' => $category,
178 ]); 189 ]);
179 } 190 }
180 191
frontend/views/catalog/product.php
1 <?php 1 <?php
  2 + /**
  3 + * @var Category $category
  4 + */
2 // use common\modules\comment\models\Comment; 5 // use common\modules\comment\models\Comment;
3 // use common\modules\comment\models\Rating; 6 // use common\modules\comment\models\Rating;
4 // use common\modules\comment\widgets\CommentWidget; 7 // use common\modules\comment\widgets\CommentWidget;
5 use common\modules\comment\widgets\CommentWidget; 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 use yii\web\View; 10 use yii\web\View;
11 use yii\helpers\Url; 11 use yii\helpers\Url;
12 use frontend\widgets\Seo; 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 $this->params[ 'seo' ][ 'fields' ][ 'name' ] = $product->fullname; 15 $this->params[ 'seo' ][ 'fields' ][ 'name' ] = $product->fullname;
16 $this->params[ 'seo' ][ 'h1' ] = !empty( Seo::widget([ 'row' => 'h1' ]) ) ? Seo::widget([ 'row' => 'h1' ]) : $product->fullname; 16 $this->params[ 'seo' ][ 'h1' ] = !empty( Seo::widget([ 'row' => 'h1' ]) ) ? Seo::widget([ 'row' => 'h1' ]) : $product->fullname;
17 17
@@ -30,10 +30,10 @@ @@ -30,10 +30,10 @@
30 'url' => [ 'catalog/category' ], 30 'url' => [ 'catalog/category' ],
31 ]; 31 ];
32 $this->params[ 'breadcrumbs' ][] = [ 32 $this->params[ 'breadcrumbs' ][] = [
33 - 'label' => $product->category->categoryName->value, 33 + 'label' => $category->categoryName->value,
34 'url' => [ 34 'url' => [
35 'catalog/category', 35 'catalog/category',
36 - 'category' => $product->category, 36 + 'category' => $category,
37 ], 37 ],
38 ]; 38 ];
39 $this->params[ 'breadcrumbs' ][] = $product->fullname . ' #' . $product->enabledVariants[ 0 ]->sku; 39 $this->params[ 'breadcrumbs' ][] = $product->fullname . ' #' . $product->enabledVariants[ 0 ]->sku;
@@ -126,8 +126,8 @@ @@ -126,8 +126,8 @@
126 data-imageoriginal="<?= $variant->imageUrl ?>" 126 data-imageoriginal="<?= $variant->imageUrl ?>"
127 title="<?= $product->fullname ?>"> 127 title="<?= $product->fullname ?>">
128 <?= \common\components\artboximage\ArtboxImageHelper::getImage($variant->imageUrl, 'product_variant', [ 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 </a> 132 </a>
133 </li> 133 </li>
@@ -228,7 +228,7 @@ @@ -228,7 +228,7 @@
228 <li><a href="#">Характеристики</a> 228 <li><a href="#">Характеристики</a>
229 <div class="info"> 229 <div class="info">
230 <p>Бренд: <?= $product->brand->name ?></p> 230 <p>Бренд: <?= $product->brand->name ?></p>
231 - <?php foreach($product->activeProperties as $group): ?> 231 + <?php foreach($product->getActiveProperties($category->category_id) as $group): ?>
232 <p><?= $group->name ?> <?php foreach($group->_options as $option) : ?>&nbsp;<?= $option->ValueRenderHTML ?><?php endforeach ?></p> 232 <p><?= $group->name ?> <?php foreach($group->_options as $option) : ?>&nbsp;<?= $option->ValueRenderHTML ?><?php endforeach ?></p>
233 <?php endforeach; ?> 233 <?php endforeach; ?>
234 </div> 234 </div>
@@ -262,8 +262,8 @@ @@ -262,8 +262,8 @@
262 <center> 262 <center>
263 <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[ 0 ]->imageUrl, 'product_view', [ 263 <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[ 0 ]->imageUrl, 'product_view', [
264 'id' => 'pic', 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 ]) ?></a> 267 ]) ?></a>
268 </center> 268 </center>
269 </div> 269 </div>
@@ -271,8 +271,8 @@ @@ -271,8 +271,8 @@
271 <?php foreach($product->images as $image): ?> 271 <?php foreach($product->images as $image): ?>
272 <li><a href="<?= $image->imageUrl ?>" rel="shadowbox[gal]"> 272 <li><a href="<?= $image->imageUrl ?>" rel="shadowbox[gal]">
273 <?= \common\components\artboximage\ArtboxImageHelper::getImage($image->imageUrl, 'product_trumb2', [ 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 </a></li> 277 </a></li>
278 <?php endforeach; ?> 278 <?php endforeach; ?>
frontend/views/search/index.php
@@ -21,17 +21,6 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = [&#39;label&#39; =&gt; &#39;Поиск&#39;, &#39;url&#39; =&gt; [&#39;catalog/ca @@ -21,17 +21,6 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = [&#39;label&#39; =&gt; &#39;Поиск&#39;, &#39;url&#39; =&gt; [&#39;catalog/ca
21 $this->params['seo']['meta']= 'noindex,follow'; 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 <div class="loyout"> 24 <div class="loyout">
36 <?php if(!empty($categories)) :?> 25 <?php if(!empty($categories)) :?>
37 <div class="leftbar"> 26 <div class="leftbar">