Commit c67585d715a91088d20849bd76fa8cea36e4ee37
1 parent
51819516
Category path fixes
Showing
8 changed files
with
264 additions
and
20 deletions
Show diff stats
common/modules/product/models/Category.php
| @@ -14,9 +14,7 @@ | @@ -14,9 +14,7 @@ | ||
| 14 | 14 | ||
| 15 | /** | 15 | /** |
| 16 | * This is the model class for table "category". | 16 | * This is the model class for table "category". |
| 17 | - * | ||
| 18 | * @todo Write doc for ArtboxTreeBehavior | 17 | * @todo Write doc for ArtboxTreeBehavior |
| 19 | - * | ||
| 20 | * @property integer $category_id | 18 | * @property integer $category_id |
| 21 | * @property integer $remote_id | 19 | * @property integer $remote_id |
| 22 | * @property integer $parent_id | 20 | * @property integer $parent_id |
| @@ -24,6 +22,7 @@ | @@ -24,6 +22,7 @@ | ||
| 24 | * @property integer $depth | 22 | * @property integer $depth |
| 25 | * @property string $image | 23 | * @property string $image |
| 26 | * @property integer $product_unit_id | 24 | * @property integer $product_unit_id |
| 25 | + * @property Brand[] $activeBrands | ||
| 27 | * * From language behavior * | 26 | * * From language behavior * |
| 28 | * @property CategoryLang $lang | 27 | * @property CategoryLang $lang |
| 29 | * @property CategoryLang[] $langs | 28 | * @property CategoryLang[] $langs |
| @@ -155,7 +154,16 @@ | @@ -155,7 +154,16 @@ | ||
| 155 | ->select('brand.*') | 154 | ->select('brand.*') |
| 156 | ->joinWith('brand') | 155 | ->joinWith('brand') |
| 157 | ->groupBy('brand.brand_id'); | 156 | ->groupBy('brand.brand_id'); |
| 158 | - | 157 | + } |
| 158 | + | ||
| 159 | + /** | ||
| 160 | + * Improved getBrands() | ||
| 161 | + * @return ActiveQuery | ||
| 162 | + */ | ||
| 163 | + public function getActiveBrands() | ||
| 164 | + { | ||
| 165 | + return $this->hasMany(Brand::className(), [ 'brand_id' => 'brand_id' ]) | ||
| 166 | + ->via('products'); | ||
| 159 | } | 167 | } |
| 160 | 168 | ||
| 161 | public function getTaxGroupsByLevel($level) | 169 | public function getTaxGroupsByLevel($level) |
common/translation/ru/app.php
| @@ -182,4 +182,5 @@ return [ | @@ -182,4 +182,5 @@ return [ | ||
| 182 | 'Поиск' => 'Поиск', | 182 | 'Поиск' => 'Поиск', |
| 183 | 'Результаты поиска для' => 'Результаты поиска для', | 183 | 'Результаты поиска для' => 'Результаты поиска для', |
| 184 | 'certs' => 'Сертификаты', | 184 | 'certs' => 'Сертификаты', |
| 185 | + 'All-list ' => 'Весь ', | ||
| 185 | ]; | 186 | ]; |
| 186 | \ No newline at end of file | 187 | \ No newline at end of file |
common/translation/ua/app.php
| @@ -182,4 +182,5 @@ return [ | @@ -182,4 +182,5 @@ return [ | ||
| 182 | 'Поиск' => 'Пошук', | 182 | 'Поиск' => 'Пошук', |
| 183 | 'Результаты поиска для' => 'Результати пошуку для', | 183 | 'Результаты поиска для' => 'Результати пошуку для', |
| 184 | 'certs' => 'Сертифікати', | 184 | 'certs' => 'Сертифікати', |
| 185 | + 'All-list ' => 'Весь ', | ||
| 185 | ]; | 186 | ]; |
| 186 | \ No newline at end of file | 187 | \ No newline at end of file |
frontend/controllers/FilterController.php
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | use common\modules\product\models\Category; | 6 | use common\modules\product\models\Category; |
| 7 | use common\modules\product\models\ProductSearch; | 7 | use common\modules\product\models\ProductSearch; |
| 8 | use common\modules\rubrication\models\TaxOption; | 8 | use common\modules\rubrication\models\TaxOption; |
| 9 | + use yii\db\ActiveQuery; | ||
| 9 | use yii\web\Controller; | 10 | use yii\web\Controller; |
| 10 | use yii\web\NotFoundHttpException; | 11 | use yii\web\NotFoundHttpException; |
| 11 | 12 | ||
| @@ -38,11 +39,13 @@ | @@ -38,11 +39,13 @@ | ||
| 38 | 39 | ||
| 39 | /** | 40 | /** |
| 40 | * Filter by type. | 41 | * Filter by type. |
| 42 | + * | ||
| 41 | * @return string | 43 | * @return string |
| 42 | */ | 44 | */ |
| 43 | public function actionCategory($id) | 45 | public function actionCategory($id) |
| 44 | { | 46 | { |
| 45 | $category = $this->findCategory($id); | 47 | $category = $this->findCategory($id); |
| 48 | + $brandsAll = $category->activeBrands; | ||
| 46 | $purposes = TaxOption::find() | 49 | $purposes = TaxOption::find() |
| 47 | ->joinWith('lang', true, 'INNER JOIN') | 50 | ->joinWith('lang', true, 'INNER JOIN') |
| 48 | ->joinWith([ | 51 | ->joinWith([ |
| @@ -80,14 +83,16 @@ | @@ -80,14 +83,16 @@ | ||
| 80 | } | 83 | } |
| 81 | } | 84 | } |
| 82 | return $this->render('category', [ | 85 | return $this->render('category', [ |
| 83 | - 'category' => $category, | ||
| 84 | - 'purposes' => $purposes, | ||
| 85 | - 'brands' => $brands, | 86 | + 'category' => $category, |
| 87 | + 'purposes' => $purposes, | ||
| 88 | + 'brands' => $brands, | ||
| 89 | + 'brandsAll' => $brandsAll, | ||
| 86 | ]); | 90 | ]); |
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | /** | 93 | /** |
| 90 | * Filter by purpose. | 94 | * Filter by purpose. |
| 95 | + * | ||
| 91 | * @return string | 96 | * @return string |
| 92 | */ | 97 | */ |
| 93 | public function actionPurpose($id) | 98 | public function actionPurpose($id) |
| @@ -136,6 +141,9 @@ | @@ -136,6 +141,9 @@ | ||
| 136 | $searchModel = new ProductSearch(); | 141 | $searchModel = new ProductSearch(); |
| 137 | $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | 142 | $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); |
| 138 | $dataProvider->pagination = false; | 143 | $dataProvider->pagination = false; |
| 144 | + /** | ||
| 145 | + * @var ActiveQuery $query | ||
| 146 | + */ | ||
| 139 | $query = $dataProvider->query; | 147 | $query = $dataProvider->query; |
| 140 | $query->with('variants.lang') | 148 | $query->with('variants.lang') |
| 141 | ->joinWith('brand.lang') | 149 | ->joinWith('brand.lang') |
| @@ -155,6 +163,42 @@ | @@ -155,6 +163,42 @@ | ||
| 155 | ]); | 163 | ]); |
| 156 | } | 164 | } |
| 157 | 165 | ||
| 166 | + public function actionCategoryBrand($category_id, $brand_id) | ||
| 167 | + { | ||
| 168 | + $category = $this->findCategory($category_id); | ||
| 169 | + $brand = $this->findBrand($brand_id); | ||
| 170 | + $searchModel = new ProductSearch(); | ||
| 171 | + $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | ||
| 172 | + $dataProvider->pagination = false; | ||
| 173 | + /** | ||
| 174 | + * @var ActiveQuery $query | ||
| 175 | + */ | ||
| 176 | + $query = $dataProvider->query; | ||
| 177 | + $query->with('variants.lang') | ||
| 178 | + ->joinWith('brand.lang') | ||
| 179 | + ->joinWith('categories.lang') | ||
| 180 | + ->andWhere([ | ||
| 181 | + 'category.category_id' => $category->category_id, | ||
| 182 | + 'brand.brand_id' => $brand->brand_id, | ||
| 183 | + ]); | ||
| 184 | + return $this->render('category-brand', [ | ||
| 185 | + 'category' => $category, | ||
| 186 | + 'brand' => $brand, | ||
| 187 | + 'searchModel' => $searchModel, | ||
| 188 | + 'dataProvider' => $dataProvider, | ||
| 189 | + ]); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + public function actionCategoryBrands($category_id) | ||
| 193 | + { | ||
| 194 | + $category = $this->findCategory($category_id); | ||
| 195 | + $brands = $category->activeBrands; | ||
| 196 | + return $this->render('category-brands', [ | ||
| 197 | + 'category' => $category, | ||
| 198 | + 'brands' => $brands, | ||
| 199 | + ]); | ||
| 200 | + } | ||
| 201 | + | ||
| 158 | /** | 202 | /** |
| 159 | * @param $id | 203 | * @param $id |
| 160 | * | 204 | * |
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * @var View $this | ||
| 4 | + * @var Category $category | ||
| 5 | + * @var TaxOption $purpose | ||
| 6 | + * @var Brand $brand | ||
| 7 | + * @var ProductSearch $searchModel | ||
| 8 | + * @var ActiveDataProvider $dataProvider | ||
| 9 | + */ | ||
| 10 | + use common\components\artboximage\ArtboxImageHelper; | ||
| 11 | + use common\modules\product\models\Brand; | ||
| 12 | + use common\modules\product\models\Category; | ||
| 13 | + use common\modules\product\models\ProductSearch; | ||
| 14 | + use common\modules\rubrication\models\TaxOption; | ||
| 15 | + use yii\data\ActiveDataProvider; | ||
| 16 | + use yii\web\View; | ||
| 17 | + use yii\widgets\ListView; | ||
| 18 | + | ||
| 19 | + $this->title = $category->lang->name . ' ' . $brand->lang->name . ' ' . mb_strtolower($purpose->lang->value); | ||
| 20 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 21 | + 'label' => $category->lang->name, | ||
| 22 | + 'url' => [ | ||
| 23 | + 'filter/category', | ||
| 24 | + 'id' => $category->category_id, | ||
| 25 | + ], | ||
| 26 | + ]; | ||
| 27 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 28 | + 'label' => $purpose->lang->value, | ||
| 29 | + 'url' => [ | ||
| 30 | + 'filter/purpose', | ||
| 31 | + 'id' => $purpose->tax_option_id, | ||
| 32 | + ], | ||
| 33 | + ]; | ||
| 34 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 35 | + 'label' => $category->lang->name . ' ' . mb_strtolower($purpose->lang->value), | ||
| 36 | + 'url' => [ | ||
| 37 | + 'filter/index', | ||
| 38 | + 'category_id' => $category->category_id, | ||
| 39 | + 'purpose_id' => $purpose->tax_option_id, | ||
| 40 | + ], | ||
| 41 | + ]; | ||
| 42 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 43 | +?> | ||
| 44 | +<div class="section-box box-title-1 uppercase"><?= $this->title ?></div> | ||
| 45 | +<div class="section-box box-brand margin_bottom_30"> | ||
| 46 | + <div class="row"> | ||
| 47 | + <div class="style" style="position: relative"> | ||
| 48 | + <div class="col-xs-12 col-sm-6 col-md-6"> | ||
| 49 | + <div class="style article-img"> | ||
| 50 | + <?php | ||
| 51 | + echo ArtboxImageHelper::getImage($category->getImageUrl(), 'article_list'); | ||
| 52 | + ?> | ||
| 53 | + </div> | ||
| 54 | + </div> | ||
| 55 | + <div class="col-xs-12 col-sm-6 col-md-6" style="position: relative;z-index: 2"> | ||
| 56 | + <div class="style brand-main-txt"> | ||
| 57 | + <?php | ||
| 58 | + echo $brand->lang->seo_text; | ||
| 59 | + ?> | ||
| 60 | + </div> | ||
| 61 | + </div> | ||
| 62 | + <div class="brand-txt-img"> | ||
| 63 | + <?php | ||
| 64 | + echo ArtboxImageHelper::getImage($brand->getImageUrl(), 'brand_image_filter'); | ||
| 65 | + ?> | ||
| 66 | + </div> | ||
| 67 | + </div> | ||
| 68 | + <?php | ||
| 69 | + echo ListView::widget([ | ||
| 70 | + 'dataProvider' => $dataProvider, | ||
| 71 | + 'itemView' => '_brand_item', | ||
| 72 | + 'itemOptions' => [ | ||
| 73 | + 'class' => 'brands-list_', | ||
| 74 | + ], | ||
| 75 | + 'options' => [ | ||
| 76 | + 'class' => 'style brands-list-wr', | ||
| 77 | + ], | ||
| 78 | + 'layout' => '{items}', | ||
| 79 | + ]); | ||
| 80 | + ?> | ||
| 81 | + </div> | ||
| 82 | +</div> | ||
| 0 | \ No newline at end of file | 83 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * @var $this yii\web\View | ||
| 4 | + * @var Category $category | ||
| 5 | + * @var Brand[] $brands | ||
| 6 | + */ | ||
| 7 | + use common\components\artboximage\ArtboxImageHelper; | ||
| 8 | + use common\modules\product\models\Brand; | ||
| 9 | + use common\modules\product\models\Category; | ||
| 10 | + use yii\helpers\Html; | ||
| 11 | + | ||
| 12 | + $this->title = \Yii::t('product', 'Brands').' '.$category->lang->name; | ||
| 13 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 14 | + 'label' => $category->lang->name, | ||
| 15 | + 'url' => [ | ||
| 16 | + 'filter/category', | ||
| 17 | + 'id' => $category->category_id, | ||
| 18 | + ], | ||
| 19 | + ]; | ||
| 20 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 21 | +?> | ||
| 22 | +<div class="section-box box-title-1 uppercase"><?= $this->title; ?></div> | ||
| 23 | +<div class="section-box box-brand margin_bottom_30"> | ||
| 24 | + <div class="row"> | ||
| 25 | + <div class="col-xs-12 col-sm-9 col-md-7 col-lg-7"> | ||
| 26 | + <div class="style article-img"> | ||
| 27 | + <?php | ||
| 28 | + echo ArtboxImageHelper::getImage($category->getImageUrl(), 'full_filter'); | ||
| 29 | + ?> | ||
| 30 | + </div> | ||
| 31 | + <div class="style content-txt"> | ||
| 32 | + <?php | ||
| 33 | + echo $category->lang->seo_text; | ||
| 34 | + ?> | ||
| 35 | + </div> | ||
| 36 | + </div> | ||
| 37 | + <div class="col-xs-12 col-sm-1 col-md-1 col-lg-1 hidden-sm hidden-xs"></div> | ||
| 38 | + <div class="col-xs-12 col-sm-3 col-md-3 col-lg-2"> | ||
| 39 | + <div class="brand-link"> | ||
| 40 | + <?php | ||
| 41 | + foreach($brands as $brand) { | ||
| 42 | + echo Html::a(ArtboxImageHelper::getImage($brand->getImageUrl(), 'brand_image_filter'), [ | ||
| 43 | + 'filter/category-brand', | ||
| 44 | + 'category_id' => $category->category_id, | ||
| 45 | + 'brand_id' => $brand->brand_id, | ||
| 46 | + ]); | ||
| 47 | + } | ||
| 48 | + ?> | ||
| 49 | + </div> | ||
| 50 | + </div> | ||
| 51 | + </div> | ||
| 52 | +</div> | ||
| 0 | \ No newline at end of file | 53 | \ No newline at end of file |
frontend/views/filter/category.php
| 1 | <?php | 1 | <?php |
| 2 | + | ||
| 3 | + use common\components\artboximage\ArtboxImageHelper; | ||
| 4 | + use common\modules\product\models\Brand; | ||
| 5 | + use common\modules\product\models\Category; | ||
| 6 | + use common\modules\rubrication\models\TaxOption; | ||
| 7 | + use yii\helpers\Html; | ||
| 8 | + | ||
| 2 | /** | 9 | /** |
| 3 | * @var $this yii\web\View | 10 | * @var $this yii\web\View |
| 4 | * @var Category $category | 11 | * @var Category $category |
| 5 | * @var TaxOption[] $purposes | 12 | * @var TaxOption[] $purposes |
| 6 | * @var array $brands | 13 | * @var array $brands |
| 14 | + * @var Brand[] $brandsAll | ||
| 7 | */ | 15 | */ |
| 8 | - use common\components\artboximage\ArtboxImageHelper; | ||
| 9 | - use common\modules\product\models\Brand; | ||
| 10 | - use common\modules\product\models\Category; | ||
| 11 | - use common\modules\rubrication\models\TaxOption; | ||
| 12 | - use yii\helpers\Html; | ||
| 13 | 16 | ||
| 14 | $this->title = $category->lang->name; | 17 | $this->title = $category->lang->name; |
| 15 | $this->params[ 'breadcrumbs' ][] = $this->title; | 18 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| @@ -18,6 +21,53 @@ | @@ -18,6 +21,53 @@ | ||
| 18 | <div class="section-box box-category margin_bottom_30"> | 21 | <div class="section-box box-category margin_bottom_30"> |
| 19 | <div class="row"> | 22 | <div class="row"> |
| 20 | <?php | 23 | <?php |
| 24 | + if(!empty( $brandsAll )) { | ||
| 25 | + ?> | ||
| 26 | + <div class="cat-list-wr col-xs-12 col-sm-4 col-md-4 col-lg-3"> | ||
| 27 | + <div class="cat-list"> | ||
| 28 | + <?php | ||
| 29 | + echo Html::a(Html::tag('p', \Yii::t('app', 'All-list ').$category->lang->name), [ | ||
| 30 | + 'filter/category-brands', | ||
| 31 | + 'category_id' => $category->category_id, | ||
| 32 | + ], [ | ||
| 33 | + 'class' => 'link-cat', | ||
| 34 | + 'style' => 'background-image: url("' . ArtboxImageHelper::getImageSrc($category->getImageUrl(), 'filter_image') . '")', | ||
| 35 | + ]); | ||
| 36 | + ?> | ||
| 37 | + <div class="cat-list-brands-wr"> | ||
| 38 | + <div class="cat-list-brands"> | ||
| 39 | + <ul> | ||
| 40 | + <?php | ||
| 41 | + foreach($brandsAll as $brand) { | ||
| 42 | + /** | ||
| 43 | + * @var Brand $brand | ||
| 44 | + */ | ||
| 45 | + echo Html::tag('li', Html::a($brand->lang->name, [ | ||
| 46 | + 'filter/category-brand', | ||
| 47 | + 'category_id' => $category->category_id, | ||
| 48 | + 'brand_id' => $brand->brand_id, | ||
| 49 | + ])); | ||
| 50 | + } | ||
| 51 | + ?> | ||
| 52 | + </ul> | ||
| 53 | + <?php | ||
| 54 | + if(count($brandsAll) > 5) { | ||
| 55 | + ?> | ||
| 56 | + <div class="expand_brands"> | ||
| 57 | + <p><?php echo \Yii::t('app', 'развернуть'); ?></p></div> | ||
| 58 | + <?php | ||
| 59 | + } | ||
| 60 | + ?> | ||
| 61 | + <!--если список больше 5 то выводим блок .expand_brands--> | ||
| 62 | + <!--------------------------------------------------------> | ||
| 63 | + </div> | ||
| 64 | + </div> | ||
| 65 | + </div> | ||
| 66 | + </div> | ||
| 67 | + <?php | ||
| 68 | + } | ||
| 69 | + ?> | ||
| 70 | + <?php | ||
| 21 | foreach($purposes as $purpose) { | 71 | foreach($purposes as $purpose) { |
| 22 | ?> | 72 | ?> |
| 23 | <div class="cat-list-wr col-xs-12 col-sm-4 col-md-4 col-lg-3"> | 73 | <div class="cat-list-wr col-xs-12 col-sm-4 col-md-4 col-lg-3"> |
frontend/views/layouts/main.php
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | 7 | ||
| 8 | use common\models\Page; | 8 | use common\models\Page; |
| 9 | use common\modules\language\models\Language; | 9 | use common\modules\language\models\Language; |
| 10 | - use common\modules\product\models\Category; | 10 | + use common\modules\rubrication\models\TaxGroup; |
| 11 | use yii\helpers\Html; | 11 | use yii\helpers\Html; |
| 12 | use frontend\assets\AppAsset; | 12 | use frontend\assets\AppAsset; |
| 13 | use yii\widgets\ActiveForm; | 13 | use yii\widgets\ActiveForm; |
| @@ -37,17 +37,23 @@ | @@ -37,17 +37,23 @@ | ||
| 37 | ], | 37 | ], |
| 38 | ]; | 38 | ]; |
| 39 | } | 39 | } |
| 40 | - $categories = Category::find() | ||
| 41 | - ->joinWith('lang', true, 'INNER JOIN') | ||
| 42 | - ->where([ 'depth' => 0 ]) | ||
| 43 | - ->all(); | 40 | + /** |
| 41 | + * @var TaxGroup $purposes | ||
| 42 | + */ | ||
| 43 | + $purposes = TaxGroup::find() | ||
| 44 | + ->where([ | ||
| 45 | + 'tax_group.tax_group_id' => 5, | ||
| 46 | + 'level' => 0, | ||
| 47 | + ]) | ||
| 48 | + ->joinWith('options.lang') | ||
| 49 | + ->one(); | ||
| 44 | $submenu_items = []; | 50 | $submenu_items = []; |
| 45 | - foreach($categories as $category) { | 51 | + foreach($purposes->options as $option) { |
| 46 | $submenu_items[] = [ | 52 | $submenu_items[] = [ |
| 47 | - 'label' => $category->lang->name, | 53 | + 'label' => $option->lang->value, |
| 48 | 'url' => [ | 54 | 'url' => [ |
| 49 | - 'filter/category', | ||
| 50 | - 'id' => $category->category_id, | 55 | + 'filter/purpose', |
| 56 | + 'id' => $option->tax_option_id, | ||
| 51 | ], | 57 | ], |
| 52 | ]; | 58 | ]; |
| 53 | } | 59 | } |