diff --git a/common/config/main.php b/common/config/main.php index f8aac3d..2c8ebef 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -233,6 +233,12 @@ 'height' => 221, ], ], + 'product_list_item' => [ + 'resize' => [ + 'width' => 308, + 'height' => 221, + ], + ], ] ], 'basket' => [ diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index dc5dc39..29971d2 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -292,4 +292,13 @@ class Category extends \yii\db\ActiveRecord 'category_id' => 'parent_id', ]); } + + public function getGrandParent() + { + return $this->hasOne(Category::className(), [ + 'category_id' => 'parent_id', + ])->viaTable('category', [ + 'category_id' => 'parent_id', + ], function($query) { $query->from('category c2'); }); + } } diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index 3a6fc29..ba005a3 100755 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -1,8 +1,10 @@ render('index'); + $category = Category::find() + ->where([ + 'category_id' => $id, + ])->one(); + $query = Product::find() + ->joinWith(['categories.grandParent c3']) + ->with('variant') + ->where(['c3.category_id' => $id]); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 15, + ], + ]); + return $this->render('index', [ + 'dataProvider' => $dataProvider, + 'category' => $category, + ]); } /** diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index f0c13f1..9ca4ea7 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -56,15 +56,15 @@ $brands = Category::find()