Commit ee968c151e53268c985f3345c407a9586a732c71

Authored by Yarik
1 parent 3a00e6d1

Filters

common/config/main.php
1 <?php 1 <?php
  2 + use artbox\catalog\helpers\FilterHelper;
2 use artbox\core\components\SeoComponent; 3 use artbox\core\components\SeoComponent;
3 4
4 return [ 5 return [
@@ -24,11 +25,7 @@ @@ -24,11 +25,7 @@
24 'translations' => [ 25 'translations' => [
25 'core' => [ 26 'core' => [
26 'class' => 'yii\i18n\PhpMessageSource', 27 'class' => 'yii\i18n\PhpMessageSource',
27 - 'basePath' => '@artbox/catalog/messages',  
28 - ],  
29 - 'catalog' => [  
30 - 'class' => 'yii\i18n\PhpMessageSource',  
31 - 'basePath' => '@artbox/catalog/messages', 28 + 'basePath' => '@artbox/core/messages',
32 ], 29 ],
33 'catalog' => [ 30 'catalog' => [
34 'class' => 'yii\i18n\PhpMessageSource', 31 'class' => 'yii\i18n\PhpMessageSource',
@@ -52,6 +49,9 @@ @@ -52,6 +49,9 @@
52 'seo' => [ 49 'seo' => [
53 'class' => SeoComponent::className(), 50 'class' => SeoComponent::className(),
54 ], 51 ],
  52 + 'filter' => [
  53 + 'class' => FilterHelper::className(),
  54 + ],
55 'imagemanager' => [ 55 'imagemanager' => [
56 'class' => 'noam148\imagemanager\components\ImageManagerGetPath', 56 'class' => 'noam148\imagemanager\components\ImageManagerGetPath',
57 'mediaPath' => dirname(dirname(__DIR__)) . '/common/images', 57 'mediaPath' => dirname(dirname(__DIR__)) . '/common/images',
frontend/config/main.php
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 'request' => [ 19 'request' => [
20 'class' => LanguageRequest::className(), 20 'class' => LanguageRequest::className(),
21 'csrfParam' => '_csrf-frontend', 21 'csrfParam' => '_csrf-frontend',
22 - 'baseUrl' => '', 22 + 'baseUrl' => '/',
23 ], 23 ],
24 'user' => [ 24 'user' => [
25 'identityClass' => 'common\models\User', 25 'identityClass' => 'common\models\User',
@@ -49,11 +49,17 @@ @@ -49,11 +49,17 @@
49 'errorAction' => 'site/error', 49 'errorAction' => 'site/error',
50 ], 50 ],
51 'urlManager' => [ 51 'urlManager' => [
  52 + 'baseUrl' => '/',
52 'class' => SeoUrlManager::className(), 53 'class' => SeoUrlManager::className(),
53 'enablePrettyUrl' => true, 54 'enablePrettyUrl' => true,
54 'showScriptName' => false, 55 'showScriptName' => false,
55 'rules' => [ 56 'rules' => [
56 - '\/robots.txt' => 'site/robots', 57 + [
  58 + 'pattern' => 'filter/<filter>',
  59 + 'route' => 'filter/index',
  60 + 'defaults' => [ 'filter' => '' ],
  61 + ],
  62 + 'robots.txt' => 'site/robots',
57 ], 63 ],
58 ], 64 ],
59 ], 65 ],
frontend/controllers/FilterController.php 0 → 100755
  1 +<?php
  2 + namespace frontend\controllers;
  3 +
  4 + use artbox\catalog\helpers\FilterHelper;
  5 + use artbox\catalog\models\Category;
  6 + use yii\data\ActiveDataProvider;
  7 + use yii\web\Controller;
  8 + use yii\web\NotFoundHttpException;
  9 +
  10 + /**
  11 + * Class FilterController
  12 + */
  13 + class FilterController extends Controller
  14 + {
  15 + public function actionIndex($filter, $category_id)
  16 + {
  17 + $category = $this->findCategory($category_id);
  18 + /**
  19 + * @var FilterHelper $filterHelper
  20 + */
  21 + $filterHelper = \Yii::$app->get('filter');
  22 + $filterHelper->setFilter($filter);
  23 + $query = $filterHelper->buildQuery();
  24 + $dataProvider = new ActiveDataProvider(
  25 + [
  26 + 'query' => $query,
  27 + ]
  28 + );
  29 + return $this->render(
  30 + 'index',
  31 + [
  32 + 'dataProvider' => $dataProvider,
  33 + 'category' => $category,
  34 + ]
  35 + );
  36 + }
  37 +
  38 + protected function findCategory($id)
  39 + {
  40 + if ($model = Category::findWithFilters($id)
  41 + ->one()
  42 + ) {
  43 + return $model;
  44 + } else {
  45 + throw new NotFoundHttpException();
  46 + }
  47 + }
  48 + }
0 \ No newline at end of file 49 \ No newline at end of file
frontend/views/filter/index.php 0 → 100644
  1 +<?php
  2 + use artbox\catalog\helpers\FilterHelper;
  3 + use artbox\catalog\models\Brand;
  4 + use artbox\catalog\models\Category;
  5 + use artbox\catalog\models\Product;
  6 + use yii\bootstrap\Html;
  7 + use yii\data\ActiveDataProvider;
  8 +
  9 + /**
  10 + * @var ActiveDataProvider $dataProvider
  11 + * @var Category $category
  12 + * @var FilterHelper $filterHelper
  13 + */
  14 + $filterHelper = \Yii::$app->get('filter');
  15 +?>
  16 +<div class="row">
  17 + <div class="col-xs-6">
  18 + <div class="panel">
  19 + <div class="panel-heading">
  20 + <h3>Brand</h3>
  21 + </div>
  22 + <div class="panel-body">
  23 + <div class="form-group">
  24 + <?php
  25 + foreach ($filterHelper->getBrands($category) as $brand) {
  26 + /**
  27 + * @var Product $product
  28 + * @var Brand $brand
  29 + */
  30 + echo Html::tag(
  31 + 'div',
  32 + Html::tag(
  33 + 'label',
  34 + $brand->lang->title . ': ' . Html::a(
  35 + $filterHelper->buildLink($brand),
  36 + [
  37 + '/filter/index',
  38 + 'filter' => $filterHelper->buildLink($brand),
  39 + 'category_id' => $category->id,
  40 + ]
  41 + )
  42 + ),
  43 + [
  44 + 'class' => 'checkbox',
  45 + ]
  46 + );
  47 + }
  48 + ?>
  49 + </div>
  50 + </div>
  51 + </div>
  52 + <?php
  53 + foreach ($category->productOptionGroupCompls as $group) {
  54 + ?>
  55 + <div class="panel">
  56 + <div class="panel-heading">
  57 + <h3><?php echo $group->lang->title; ?></h3>
  58 + </div>
  59 + <div class="panel-body">
  60 + <div class="form-group">
  61 + <?php
  62 + foreach ($group->options as $option) {
  63 + /**
  64 + * @var Product $product
  65 + */
  66 + echo Html::tag(
  67 + 'div',
  68 + Html::tag(
  69 + 'label',
  70 + $option->lang->value . ': ' . $filterHelper->buildLink($option)
  71 + ),
  72 + [
  73 + 'class' => 'checkbox',
  74 + ]
  75 + );
  76 + }
  77 + ?>
  78 + </div>
  79 + </div>
  80 + </div>
  81 + <?php
  82 + }
  83 + foreach ($category->productOptionGroupExcls as $group) {
  84 + ?>
  85 + <div class="panel">
  86 + <div class="panel-heading">
  87 + <h3><?php echo $group->lang->title; ?></h3>
  88 + </div>
  89 + <div class="panel-body">
  90 + <div class="form-group">
  91 + <?php
  92 + foreach ($group->options as $option) {
  93 + /**
  94 + * @var Product $product
  95 + */
  96 + echo Html::tag(
  97 + 'div',
  98 + Html::tag(
  99 + 'label',
  100 + $option->lang->value . ': ' . $filterHelper->buildLink($option)
  101 + ),
  102 + [
  103 + 'class' => 'checkbox',
  104 + ]
  105 + );
  106 + }
  107 + ?>
  108 + </div>
  109 + </div>
  110 + </div>
  111 + <?php
  112 + }
  113 + foreach ($category->variantOptionGroupCompls as $group) {
  114 + ?>
  115 + <div class="panel">
  116 + <div class="panel-heading">
  117 + <h3><?php echo $group->lang->title; ?></h3>
  118 + </div>
  119 + <div class="panel-body">
  120 + <div class="form-group">
  121 + <?php
  122 + foreach ($group->options as $option) {
  123 + /**
  124 + * @var Product $product
  125 + */
  126 + echo Html::tag(
  127 + 'div',
  128 + Html::tag(
  129 + 'label',
  130 + $option->lang->value . ': ' . $filterHelper->buildLink($option)
  131 + ),
  132 + [
  133 + 'class' => 'checkbox',
  134 + ]
  135 + );
  136 + }
  137 + ?>
  138 + </div>
  139 + </div>
  140 + </div>
  141 + <?php
  142 + }
  143 + foreach ($category->variantOptionGroupExcls as $group) {
  144 + ?>
  145 + <div class="panel">
  146 + <div class="panel-heading">
  147 + <h3><?php echo $group->lang->title; ?></h3>
  148 + </div>
  149 + <div class="panel-body">
  150 + <div class="form-group">
  151 + <?php
  152 + foreach ($group->options as $option) {
  153 + /**
  154 + * @var Product $product
  155 + */
  156 + echo Html::tag(
  157 + 'div',
  158 + Html::tag(
  159 + 'label',
  160 + $option->lang->value . ': ' . $filterHelper->buildLink($option)
  161 + ),
  162 + [
  163 + 'class' => 'checkbox',
  164 + ]
  165 + );
  166 + }
  167 + ?>
  168 + </div>
  169 + </div>
  170 + </div>
  171 + <?php
  172 + }
  173 + ?>
  174 + </div>
  175 + <div class="col-xs-6">
  176 + <?php
  177 + foreach ($dataProvider->getModels() as $model) {
  178 + /**
  179 + * @var Product $model
  180 + */
  181 + echo $model->lang->title . "<br>";
  182 + }
  183 + ?>
  184 + </div>
  185 +</div>
0 \ No newline at end of file 186 \ No newline at end of file