From 020c69f520f564ace05d8a61eb7e22ce991eaaae Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Fri, 25 Mar 2016 09:58:00 +0200 Subject: [PATCH] Base-product#5 functional --- common/modules/product/models/BrandQuery.php | 11 +++++++++++ frontend/config/main.php | 1 + frontend/controllers/CatalogController.php | 15 +++++++++++++++ frontend/views/catalog/products.php | 21 +++++---------------- frontend/views/layouts/main.php | 8 +++++--- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/common/modules/product/models/BrandQuery.php b/common/modules/product/models/BrandQuery.php index a0d1273..833357d 100644 --- a/common/modules/product/models/BrandQuery.php +++ b/common/modules/product/models/BrandQuery.php @@ -31,4 +31,15 @@ class BrandQuery extends \yii\db\ActiveQuery { return parent::one($db); } + + /** + * Select brand by alias + * @param $slug + * @return $this + */ + public function byAlias($alias) + { + $this->andFilterWhere(['alias' => $alias]); + return $this; + } } diff --git a/frontend/config/main.php b/frontend/config/main.php index f5642b7..19780c2 100644 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -47,6 +47,7 @@ return [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ +// 'catalog' => 'catalog/category', 'catalog/' => 'catalog/category', 'product/' => 'catalog/product', 'brand' => 'catalog/brands', diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index 46ee77e..5da6511 100644 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -20,6 +20,10 @@ use yii\web\HttpException; class CatalogController extends \yii\web\Controller { + public function actionSearch() { + + } + public function actionCategory($alias) { $category = CategorySearch::findByAlias($alias); @@ -127,6 +131,17 @@ class CatalogController extends \yii\web\Controller } } + if (($_brands = \Yii::$app->request->get('brand')) != false && is_array($_brands) && count($_brands) > 0) { + $_brands = Brand::find()->where(['in', 'alias', $_brands])->all(); + $bids = []; + foreach ($_brands as $brand) { + $bids[] = $brand->brand_id; + } + if (count($bids)) { + $query->andWhere([Product::tableName() .'.brand_id' => $bids]); + } + } + $count = $query->count(); $pages = new Pagination(['totalCount' => $count, 'pageSize' => $per_page]); diff --git a/frontend/views/catalog/products.php b/frontend/views/catalog/products.php index 9589979..ff2e430 100644 --- a/frontend/views/catalog/products.php +++ b/frontend/views/catalog/products.php @@ -55,8 +55,8 @@ $this->params['breadcrumbs'][] = $category->name;
- - name?> (getProducts()->count()?>) + + name?>