Commit 466144f8e553921568d6c907b14f6ec4b6e49f80
1 parent
2211268d
20.07.16
Showing
3 changed files
with
42 additions
and
36 deletions
Show diff stats
backend/views/seo-dynamic/_form.php
@@ -22,19 +22,6 @@ use yii\widgets\ActiveForm; | @@ -22,19 +22,6 @@ use yii\widgets\ActiveForm; | ||
22 | 22 | ||
23 | <?= $form->field($model, 'param')->textInput(['maxlength' => true]) ?> | 23 | <?= $form->field($model, 'param')->textInput(['maxlength' => true]) ?> |
24 | 24 | ||
25 | - <!-- --><?//= $form->field($model, 'param')->dropDownList([ | ||
26 | -// 'filter' => 'filter' | ||
27 | -// ],[ 'prompt' => 'Выберите параметр...']); ?> | ||
28 | -<!-- <div>--> | ||
29 | -<!-- --><?//= | ||
30 | -// $form->field($model, 'filter_mod') | ||
31 | -// ->radioList( | ||
32 | -// ['onefilter' => 'One filter', 'twofilters' => 'Two filters', 'brand_assigment' => 'Brand and assignment '] | ||
33 | -// ) | ||
34 | -// ->label(false); | ||
35 | -// ?> | ||
36 | -<!-- </div>--> | ||
37 | - | ||
38 | <?= $form->field($model, 'key')->textInput(['maxlength' => true]) ?> | 25 | <?= $form->field($model, 'key')->textInput(['maxlength' => true]) ?> |
39 | 26 | ||
40 | <?= $form->field($model, 'fields')->textInput(['maxlength' => true]) ?> | 27 | <?= $form->field($model, 'fields')->textInput(['maxlength' => true]) ?> |
frontend/controllers/CatalogController.php
@@ -37,6 +37,7 @@ class CatalogController extends \yii\web\Controller | @@ -37,6 +37,7 @@ class CatalogController extends \yii\web\Controller | ||
37 | /** @var Category $category */ | 37 | /** @var Category $category */ |
38 | $category = Yii::$app->request->get('category'); | 38 | $category = Yii::$app->request->get('category'); |
39 | $filter = Yii::$app->request->get('filters', []); | 39 | $filter = Yii::$app->request->get('filters', []); |
40 | + $filter_check = $filter; | ||
40 | 41 | ||
41 | if (empty($category->category_id) && empty($word)) { | 42 | if (empty($category->category_id) && empty($word)) { |
42 | return $this->render( | 43 | return $this->render( |
@@ -50,6 +51,7 @@ class CatalogController extends \yii\web\Controller | @@ -50,6 +51,7 @@ class CatalogController extends \yii\web\Controller | ||
50 | $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); | 51 | $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); |
51 | 52 | ||
52 | if ( !empty($filter['brands']) ) { | 53 | if ( !empty($filter['brands']) ) { |
54 | + unset($filter_check['brands']); | ||
53 | $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); | 55 | $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); |
54 | $params['brands'] = []; | 56 | $params['brands'] = []; |
55 | foreach ($brands as $brand) { | 57 | foreach ($brands as $brand) { |
@@ -58,6 +60,7 @@ class CatalogController extends \yii\web\Controller | @@ -58,6 +60,7 @@ class CatalogController extends \yii\web\Controller | ||
58 | } | 60 | } |
59 | 61 | ||
60 | if ( !empty($filter['special']) ) { | 62 | if ( !empty($filter['special']) ) { |
63 | + unset($filter_check['special']); | ||
61 | if (!is_array($filter['special'])) { | 64 | if (!is_array($filter['special'])) { |
62 | $filter['special'] = [$filter['special']]; | 65 | $filter['special'] = [$filter['special']]; |
63 | } | 66 | } |
@@ -73,12 +76,8 @@ class CatalogController extends \yii\web\Controller | @@ -73,12 +76,8 @@ class CatalogController extends \yii\web\Controller | ||
73 | } | 76 | } |
74 | 77 | ||
75 | 78 | ||
76 | -// if ( !empty($filter['options']) ) { | ||
77 | -// $params['options'] = $filter['options']; | ||
78 | -// } | ||
79 | - | ||
80 | - | ||
81 | if ( !empty($filter['prices']) ) { | 79 | if ( !empty($filter['prices']) ) { |
80 | + unset($filter_check['prices']); | ||
82 | $params['prices'] = $filter['prices']; | 81 | $params['prices'] = $filter['prices']; |
83 | } | 82 | } |
84 | 83 | ||
@@ -87,11 +86,16 @@ class CatalogController extends \yii\web\Controller | @@ -87,11 +86,16 @@ class CatalogController extends \yii\web\Controller | ||
87 | foreach($optionsList as $optionList){ | 86 | foreach($optionsList as $optionList){ |
88 | 87 | ||
89 | if(isset($filter[$optionList])){ | 88 | if(isset($filter[$optionList])){ |
89 | + unset($filter_check[$optionList]); | ||
90 | $params[$optionList] = $filter[$optionList]; | 90 | $params[$optionList] = $filter[$optionList]; |
91 | } | 91 | } |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | + if(!empty($filter_check)){ | ||
96 | + $filter = array_diff_key($filter,$filter_check); | ||
97 | + Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filter],301); | ||
98 | + } | ||
95 | 99 | ||
96 | $productModel = new ProductFrontendSearch(); | 100 | $productModel = new ProductFrontendSearch(); |
97 | //$productQuery = $productModel->getSearchQuery($category, $params); | 101 | //$productQuery = $productModel->getSearchQuery($category, $params); |
frontend/widgets/Seo.php
@@ -4,8 +4,10 @@ namespace frontend\widgets; | @@ -4,8 +4,10 @@ namespace frontend\widgets; | ||
4 | use common\models\SeoDynamic; | 4 | use common\models\SeoDynamic; |
5 | 5 | ||
6 | use common\modules\product\models\Brand; | 6 | use common\modules\product\models\Brand; |
7 | +use common\modules\rubrication\models\TaxGroup; | ||
7 | use common\modules\rubrication\models\TaxOption; | 8 | use common\modules\rubrication\models\TaxOption; |
8 | use yii\base\Widget; | 9 | use yii\base\Widget; |
10 | +use yii\helpers\ArrayHelper; | ||
9 | use yii\helpers\Html; | 11 | use yii\helpers\Html; |
10 | 12 | ||
11 | class Seo extends Widget | 13 | class Seo extends Widget |
@@ -148,31 +150,34 @@ class Seo extends Widget | @@ -148,31 +150,34 @@ class Seo extends Widget | ||
148 | $array['brand'] = $model->name; | 150 | $array['brand'] = $model->name; |
149 | } | 151 | } |
150 | 152 | ||
151 | - if (isset($filter["pol"]) && count($filter["pol"]) == 1) { | ||
152 | 153 | ||
153 | - $model = TaxOption::find()->where(['alias' => $filter["pol"]])->one(); | ||
154 | - $array['sex'] = $model->value->value; | 154 | + $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); |
155 | 155 | ||
156 | 156 | ||
157 | - } | 157 | + foreach($optionsList as $optionList){ |
158 | 158 | ||
159 | - if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { | ||
160 | 159 | ||
161 | - $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); | ||
162 | - $array['naz'] = $model->value->value; | 160 | + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { |
163 | 161 | ||
164 | - } | 162 | + $model = TaxOption::find()->where(['alias' =>$filter[$optionList]])->one(); |
163 | + $array[$optionList] = $model->value->value; | ||
164 | + | ||
165 | + | ||
166 | + } | ||
165 | 167 | ||
166 | - if (isset($filter["god"]) && count($filter["god"]) == 1) { | ||
167 | 168 | ||
168 | - $model = TaxOption::find()->where(['alias' => $filter["god"]])->one(); | ||
169 | - $array['year'] = $model->value->value; | ||
170 | 169 | ||
171 | } | 170 | } |
172 | 171 | ||
173 | - return $this->getTitleString($array); | 172 | + $title_string = $this->getTitleString($array); |
173 | + | ||
174 | + if($title_string){ | ||
175 | + return $title_string; | ||
176 | + } | ||
174 | 177 | ||
175 | - } else if (!empty($title)) { | 178 | + } |
179 | + | ||
180 | + if (!empty($title)) { | ||
176 | return $title; | 181 | return $title; |
177 | } else { | 182 | } else { |
178 | return $this->project_name; | 183 | return $this->project_name; |
@@ -291,6 +296,11 @@ class Seo extends Widget | @@ -291,6 +296,11 @@ class Seo extends Widget | ||
291 | } | 296 | } |
292 | 297 | ||
293 | 298 | ||
299 | + protected function findSeoByDynamicForFilters(){ | ||
300 | + return SeoDynamic::find()->joinWith('seoCategory')->where(['param' =>'filters'])->one(); | ||
301 | + } | ||
302 | + | ||
303 | + | ||
294 | protected function getViewData() | 304 | protected function getViewData() |
295 | { | 305 | { |
296 | $params = $this->getView()->params; | 306 | $params = $this->getView()->params; |
@@ -331,12 +341,17 @@ class Seo extends Widget | @@ -331,12 +341,17 @@ class Seo extends Widget | ||
331 | } | 341 | } |
332 | 342 | ||
333 | public function getTitleString($array){ | 343 | public function getTitleString($array){ |
334 | - $template = "{category} {naz} {brand} {sex} {year} купить в Украине, Киев, Харькове - цены, фото, отзывы | Rukzachok.com.ua"; | ||
335 | - foreach ($array as $field_name => $field_value) { | ||
336 | - $template = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template); | 344 | + |
345 | + $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); | ||
346 | + if($template instanceof SeoDynamic){ | ||
347 | + foreach ($array as $field_name => $field_value) { | ||
348 | + $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); | ||
349 | + } | ||
350 | + $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); | ||
351 | + return $template; | ||
337 | } | 352 | } |
338 | - $template = preg_replace('/\{.[^\}]*\}\s/','',$template); | ||
339 | - return $template; | 353 | + |
354 | + return false; | ||
340 | 355 | ||
341 | } | 356 | } |
342 | 357 |