diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php index 18cbe9a..992fabd 100755 --- a/common/modules/product/helpers/ProductHelper.php +++ b/common/modules/product/helpers/ProductHelper.php @@ -292,4 +292,12 @@ return $query; } + + public static function addLastCategory($category_id) { + \Yii::$app->session->set('last_category_id', $category_id); + } + + public static function getLastCategory() { + return \Yii::$app->session->get('last_category_id'); + } } \ No newline at end of file diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index daa7958..7962c5f 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -11,6 +11,7 @@ use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use Yii; use common\modules\relation\relationBehavior; +use yii\db\ActiveQuery; use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; @@ -240,7 +241,10 @@ class Product extends \yii\db\ActiveRecord public function getVariantsWithFilters(){ return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters'); } - + + /** + * @return ActiveQuery + */ public function getCategory() { return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); } @@ -263,12 +267,12 @@ class Product extends \yii\db\ActiveRecord return $groups; } - public function getActiveProperties() { + public function getActiveProperties($category_id) { $groups = $options = []; foreach ($this->options as $option) { $options[$option->tax_group_id][] = $option; } - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options), 'display' => TRUE])->all() as $group) { + 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) { if (!empty($options[$group->tax_group_id])) { $group->_options = $options[$group->tax_group_id]; $groups[] = $group; @@ -432,6 +436,6 @@ class Product extends \yii\db\ActiveRecord public function getTaxGroupsByLevel($level) { $categories = ArrayHelper::getColumn($this->categories, 'category_id'); - return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->where(['relation.entity2_id' => $categories])->where(['level' => $level]); + return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->andWhere(['relation.entity2_id' => $categories])->andWhere(['level' => $level]); } } diff --git a/common/modules/rubrication/models/TaxGroup.php b/common/modules/rubrication/models/TaxGroup.php index ca4f842..0bc8b42 100755 --- a/common/modules/rubrication/models/TaxGroup.php +++ b/common/modules/rubrication/models/TaxGroup.php @@ -2,6 +2,7 @@ namespace common\modules\rubrication\models; +use common\modules\product\models\Category; use common\modules\relation\relationBehavior; use Yii; @@ -99,6 +100,12 @@ class TaxGroup extends \yii\db\ActiveRecord return $this->hasMany(TaxGroupToGroup::className(), ['tax_group1_id' => 'tax_group_id'])->inverseOf('taxGroup1'); } + public function getCategories() + { + return $this->hasMany(Category::className(), ['category_id' => 'entity2_id']) + ->viaTable('relation', ['entity1_id' => 'tax_group_id']); + } + /** * @return \yii\db\ActiveQuery */ diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index 937e2d5..b34677e 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -45,6 +45,8 @@ return $this->render('catalog'); } + ProductHelper::addLastCategory($category->category_id); + $params = [ ]; $optionsList = ArrayHelper::getColumn(TaxGroup::find() @@ -172,9 +174,18 @@ ProductHelper::addLastProsucts($product->product_id); + $category = null; + $last_category_id = ProductHelper::getLastCategory(); + if(!empty($last_category_id)) { + $category = $product->getCategory()->andWhere(['category_id' => $last_category_id])->one(); + } + if(empty($category)) { + $category = $product->category; + } + return $this->render('product', [ 'product' => $product, - 'category' => $product->category, + 'category' => $category, ]); } diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index cc895ae..6eea2de 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -1,17 +1,17 @@ params[ 'seo' ][ 'key' ] = $product->category->categoryName->value; + $this->params[ 'seo' ][ 'key' ] = $category->categoryName->value; $this->params[ 'seo' ][ 'fields' ][ 'name' ] = $product->fullname; $this->params[ 'seo' ][ 'h1' ] = !empty( Seo::widget([ 'row' => 'h1' ]) ) ? Seo::widget([ 'row' => 'h1' ]) : $product->fullname; @@ -30,10 +30,10 @@ 'url' => [ 'catalog/category' ], ]; $this->params[ 'breadcrumbs' ][] = [ - 'label' => $product->category->categoryName->value, + 'label' => $category->categoryName->value, 'url' => [ 'catalog/category', - 'category' => $product->category, + 'category' => $category, ], ]; $this->params[ 'breadcrumbs' ][] = $product->fullname . ' #' . $product->enabledVariants[ 0 ]->sku; @@ -126,8 +126,8 @@ data-imageoriginal="imageUrl ?>" title="fullname ?>"> imageUrl, 'product_variant', [ - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, + 'alt' => $category->categoryName->value . ' ' . $product->fullname, + 'title' => $category->categoryName->value . ' ' . $product->fullname, ]) ?> @@ -228,7 +228,7 @@
  • Характеристики

    Бренд: brand->name ?>

    - activeProperties as $group): ?> + getActiveProperties($category->category_id) as $group): ?>

    name ?> _options as $option) : ?> ValueRenderHTML ?>

    @@ -262,8 +262,8 @@
    enabledVariants[ 0 ]->imageUrl, 'product_view', [ 'id' => 'pic', - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, + 'alt' => $category->categoryName->value . ' ' . $product->fullname, + 'title' => $category->categoryName->value . ' ' . $product->fullname, ]) ?>
    @@ -271,8 +271,8 @@ images as $image): ?>
  • imageUrl, 'product_trumb2', [ - 'alt' => $product->category->categoryName->value . ' ' . $product->fullname, - 'title' => $product->category->categoryName->value . ' ' . $product->fullname, + 'alt' => $category->categoryName->value . ' ' . $product->fullname, + 'title' => $category->categoryName->value . ' ' . $product->fullname, ]) ?>
  • diff --git a/frontend/views/search/index.php b/frontend/views/search/index.php index afd0861..4285ff0 100755 --- a/frontend/views/search/index.php +++ b/frontend/views/search/index.php @@ -21,17 +21,6 @@ $this->params['breadcrumbs'][] = ['label' => 'Поиск', 'url' => ['catalog/ca $this->params['seo']['meta']= 'noindex,follow'; ?> - - -
    -- libgit2 0.21.4