From ee968c151e53268c985f3345c407a9586a732c71 Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 12 Apr 2017 19:03:22 +0300 Subject: [PATCH] Filters --- common/config/main.php | 10 +++++----- frontend/config/main.php | 10 ++++++++-- frontend/controllers/FilterController.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/filter/index.php | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 246 insertions(+), 7 deletions(-) create mode 100755 frontend/controllers/FilterController.php create mode 100644 frontend/views/filter/index.php diff --git a/common/config/main.php b/common/config/main.php index 0516561..8b1bce2 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -1,4 +1,5 @@ [ 'core' => [ 'class' => 'yii\i18n\PhpMessageSource', - 'basePath' => '@artbox/catalog/messages', - ], - 'catalog' => [ - 'class' => 'yii\i18n\PhpMessageSource', - 'basePath' => '@artbox/catalog/messages', + 'basePath' => '@artbox/core/messages', ], 'catalog' => [ 'class' => 'yii\i18n\PhpMessageSource', @@ -52,6 +49,9 @@ 'seo' => [ 'class' => SeoComponent::className(), ], + 'filter' => [ + 'class' => FilterHelper::className(), + ], 'imagemanager' => [ 'class' => 'noam148\imagemanager\components\ImageManagerGetPath', 'mediaPath' => dirname(dirname(__DIR__)) . '/common/images', diff --git a/frontend/config/main.php b/frontend/config/main.php index 7c37885..e9ad09b 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -19,7 +19,7 @@ 'request' => [ 'class' => LanguageRequest::className(), 'csrfParam' => '_csrf-frontend', - 'baseUrl' => '', + 'baseUrl' => '/', ], 'user' => [ 'identityClass' => 'common\models\User', @@ -49,11 +49,17 @@ 'errorAction' => 'site/error', ], 'urlManager' => [ + 'baseUrl' => '/', 'class' => SeoUrlManager::className(), 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ - '\/robots.txt' => 'site/robots', + [ + 'pattern' => 'filter/', + 'route' => 'filter/index', + 'defaults' => [ 'filter' => '' ], + ], + 'robots.txt' => 'site/robots', ], ], ], diff --git a/frontend/controllers/FilterController.php b/frontend/controllers/FilterController.php new file mode 100755 index 0000000..39d3b1c --- /dev/null +++ b/frontend/controllers/FilterController.php @@ -0,0 +1,48 @@ +findCategory($category_id); + /** + * @var FilterHelper $filterHelper + */ + $filterHelper = \Yii::$app->get('filter'); + $filterHelper->setFilter($filter); + $query = $filterHelper->buildQuery(); + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + ] + ); + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + 'category' => $category, + ] + ); + } + + protected function findCategory($id) + { + if ($model = Category::findWithFilters($id) + ->one() + ) { + return $model; + } else { + throw new NotFoundHttpException(); + } + } + } \ No newline at end of file diff --git a/frontend/views/filter/index.php b/frontend/views/filter/index.php new file mode 100644 index 0000000..b499365 --- /dev/null +++ b/frontend/views/filter/index.php @@ -0,0 +1,185 @@ +get('filter'); +?> +
+
+
+
+

Brand

+
+
+
+ getBrands($category) as $brand) { + /** + * @var Product $product + * @var Brand $brand + */ + echo Html::tag( + 'div', + Html::tag( + 'label', + $brand->lang->title . ': ' . Html::a( + $filterHelper->buildLink($brand), + [ + '/filter/index', + 'filter' => $filterHelper->buildLink($brand), + 'category_id' => $category->id, + ] + ) + ), + [ + 'class' => 'checkbox', + ] + ); + } + ?> +
+
+
+ productOptionGroupCompls as $group) { + ?> +
+
+

lang->title; ?>

+
+
+
+ options as $option) { + /** + * @var Product $product + */ + echo Html::tag( + 'div', + Html::tag( + 'label', + $option->lang->value . ': ' . $filterHelper->buildLink($option) + ), + [ + 'class' => 'checkbox', + ] + ); + } + ?> +
+
+
+ productOptionGroupExcls as $group) { + ?> +
+
+

lang->title; ?>

+
+
+
+ options as $option) { + /** + * @var Product $product + */ + echo Html::tag( + 'div', + Html::tag( + 'label', + $option->lang->value . ': ' . $filterHelper->buildLink($option) + ), + [ + 'class' => 'checkbox', + ] + ); + } + ?> +
+
+
+ variantOptionGroupCompls as $group) { + ?> +
+
+

lang->title; ?>

+
+
+
+ options as $option) { + /** + * @var Product $product + */ + echo Html::tag( + 'div', + Html::tag( + 'label', + $option->lang->value . ': ' . $filterHelper->buildLink($option) + ), + [ + 'class' => 'checkbox', + ] + ); + } + ?> +
+
+
+ variantOptionGroupExcls as $group) { + ?> +
+
+

lang->title; ?>

+
+
+
+ options as $option) { + /** + * @var Product $product + */ + echo Html::tag( + 'div', + Html::tag( + 'label', + $option->lang->value . ': ' . $filterHelper->buildLink($option) + ), + [ + 'class' => 'checkbox', + ] + ); + } + ?> +
+
+
+ +
+
+ getModels() as $model) { + /** + * @var Product $model + */ + echo $model->lang->title . "
"; + } + ?> +
+
\ No newline at end of file -- libgit2 0.21.4