diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 9a1c239..24efaa1 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -14,9 +14,7 @@ /** * This is the model class for table "category". - * * @todo Write doc for ArtboxTreeBehavior - * * @property integer $category_id * @property integer $remote_id * @property integer $parent_id @@ -24,6 +22,7 @@ * @property integer $depth * @property string $image * @property integer $product_unit_id + * @property Brand[] $activeBrands * * From language behavior * * @property CategoryLang $lang * @property CategoryLang[] $langs @@ -155,7 +154,16 @@ ->select('brand.*') ->joinWith('brand') ->groupBy('brand.brand_id'); - + } + + /** + * Improved getBrands() + * @return ActiveQuery + */ + public function getActiveBrands() + { + return $this->hasMany(Brand::className(), [ 'brand_id' => 'brand_id' ]) + ->via('products'); } public function getTaxGroupsByLevel($level) diff --git a/common/translation/ru/app.php b/common/translation/ru/app.php index e293b2f..ed53a55 100755 --- a/common/translation/ru/app.php +++ b/common/translation/ru/app.php @@ -182,4 +182,5 @@ return [ 'Поиск' => 'Поиск', 'Результаты поиска для' => 'Результаты поиска для', 'certs' => 'Сертификаты', + 'All-list ' => 'Весь ', ]; \ No newline at end of file diff --git a/common/translation/ua/app.php b/common/translation/ua/app.php index a348839..ad5a831 100755 --- a/common/translation/ua/app.php +++ b/common/translation/ua/app.php @@ -182,4 +182,5 @@ return [ 'Поиск' => 'Пошук', 'Результаты поиска для' => 'Результати пошуку для', 'certs' => 'Сертифікати', + 'All-list ' => 'Весь ', ]; \ No newline at end of file diff --git a/frontend/controllers/FilterController.php b/frontend/controllers/FilterController.php index dcfe0f8..a300a97 100755 --- a/frontend/controllers/FilterController.php +++ b/frontend/controllers/FilterController.php @@ -6,6 +6,7 @@ use common\modules\product\models\Category; use common\modules\product\models\ProductSearch; use common\modules\rubrication\models\TaxOption; + use yii\db\ActiveQuery; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -38,11 +39,13 @@ /** * Filter by type. + * * @return string */ public function actionCategory($id) { $category = $this->findCategory($id); + $brandsAll = $category->activeBrands; $purposes = TaxOption::find() ->joinWith('lang', true, 'INNER JOIN') ->joinWith([ @@ -80,14 +83,16 @@ } } return $this->render('category', [ - 'category' => $category, - 'purposes' => $purposes, - 'brands' => $brands, + 'category' => $category, + 'purposes' => $purposes, + 'brands' => $brands, + 'brandsAll' => $brandsAll, ]); } /** * Filter by purpose. + * * @return string */ public function actionPurpose($id) @@ -136,6 +141,9 @@ $searchModel = new ProductSearch(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); $dataProvider->pagination = false; + /** + * @var ActiveQuery $query + */ $query = $dataProvider->query; $query->with('variants.lang') ->joinWith('brand.lang') @@ -155,6 +163,42 @@ ]); } + public function actionCategoryBrand($category_id, $brand_id) + { + $category = $this->findCategory($category_id); + $brand = $this->findBrand($brand_id); + $searchModel = new ProductSearch(); + $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); + $dataProvider->pagination = false; + /** + * @var ActiveQuery $query + */ + $query = $dataProvider->query; + $query->with('variants.lang') + ->joinWith('brand.lang') + ->joinWith('categories.lang') + ->andWhere([ + 'category.category_id' => $category->category_id, + 'brand.brand_id' => $brand->brand_id, + ]); + return $this->render('category-brand', [ + 'category' => $category, + 'brand' => $brand, + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + public function actionCategoryBrands($category_id) + { + $category = $this->findCategory($category_id); + $brands = $category->activeBrands; + return $this->render('category-brands', [ + 'category' => $category, + 'brands' => $brands, + ]); + } + /** * @param $id * diff --git a/frontend/views/filter/category-brand.php b/frontend/views/filter/category-brand.php new file mode 100644 index 0000000..7b1d203 --- /dev/null +++ b/frontend/views/filter/category-brand.php @@ -0,0 +1,82 @@ +title = $category->lang->name . ' ' . $brand->lang->name . ' ' . mb_strtolower($purpose->lang->value); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $category->lang->name, + 'url' => [ + 'filter/category', + 'id' => $category->category_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $purpose->lang->value, + 'url' => [ + 'filter/purpose', + 'id' => $purpose->tax_option_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $category->lang->name . ' ' . mb_strtolower($purpose->lang->value), + 'url' => [ + 'filter/index', + 'category_id' => $category->category_id, + 'purpose_id' => $purpose->tax_option_id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +