Commit e57ad02f6f63ad94e9933a78961ee4b9e7abd653
1 parent
b7c30426
14.09.16
Showing
1 changed file
with
58 additions
and
120 deletions
Show diff stats
frontend/widgets/Seo.php
@@ -101,21 +101,49 @@ class Seo extends Widget | @@ -101,21 +101,49 @@ class Seo extends Widget | ||
101 | 101 | ||
102 | $filter = \Yii::$app->request->get('filters', []); | 102 | $filter = \Yii::$app->request->get('filters', []); |
103 | 103 | ||
104 | - $default = $this->selectSeoData(self::H1); | ||
105 | 104 | ||
106 | - if ($default != $this->{self::H1}) { | ||
107 | 105 | ||
108 | - return $default; | 106 | + if (isset($filter['brands']) && count($filter['brands']) == 1) { |
109 | 107 | ||
108 | + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); | ||
109 | + if(!$model instanceof Brand){ | ||
110 | 110 | ||
111 | - } else if(!empty($filter) && !$this->checkFilter($filter)){ | 111 | + \Yii::$app->response->redirect(['/site/error'],404); |
112 | + } else { | ||
113 | + if($this->selectSeoData(self::H1) == $this->category_name) { | ||
112 | 114 | ||
113 | - $array = $this->arrayBuilder($filter); | ||
114 | - return $this->getNameString($array); | ||
115 | - } | ||
116 | - else { | 115 | + return $this->selectSeoData(self::H1) . ' ' . $model->name ; |
116 | + }else { | ||
117 | + | ||
118 | + return $this->selectSeoData(self::H1); | ||
119 | + | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + | ||
124 | + | ||
125 | + } else if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { | ||
126 | + | ||
127 | + $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); | ||
128 | + if(!$model instanceof TaxOption){ | ||
129 | + | ||
130 | + \Yii::$app->response->redirect(['/site/error'],404); | ||
131 | + } else { | ||
132 | + if($this->selectSeoData(self::H1) == $this->category_name) { | ||
117 | 133 | ||
118 | - return $default; | 134 | + return $this->selectSeoData(self::H1) . ' ' . $model->value->value; |
135 | + }else { | ||
136 | + | ||
137 | + return $this->selectSeoData(self::H1); | ||
138 | + | ||
139 | + } | ||
140 | + | ||
141 | + } | ||
142 | + | ||
143 | + | ||
144 | + | ||
145 | + } else { | ||
146 | + return $this->selectSeoData(self::H1); | ||
119 | } | 147 | } |
120 | break; | 148 | break; |
121 | case self::TITLE: | 149 | case self::TITLE: |
@@ -192,18 +220,6 @@ class Seo extends Widget | @@ -192,18 +220,6 @@ class Seo extends Widget | ||
192 | 'content' => $description | 220 | 'content' => $description |
193 | ]); | 221 | ]); |
194 | 222 | ||
195 | - } else { | ||
196 | - | ||
197 | - $filter = \Yii::$app->request->get('filters', []); | ||
198 | - | ||
199 | - if(!empty($filter)){ | ||
200 | - $array = $this->arrayBuilder($filter); | ||
201 | - $this->getView()->registerMetaTag([ | ||
202 | - 'name' => 'description', | ||
203 | - 'content' => $this->getDescriptionString($array) | ||
204 | - ]); | ||
205 | - } | ||
206 | - | ||
207 | } | 223 | } |
208 | 224 | ||
209 | break; | 225 | break; |
@@ -211,20 +227,31 @@ class Seo extends Widget | @@ -211,20 +227,31 @@ class Seo extends Widget | ||
211 | 227 | ||
212 | $meta = $this->selectSeoData(self::META); | 228 | $meta = $this->selectSeoData(self::META); |
213 | 229 | ||
230 | + $widgetData = static::findSeoByUrl($this->url); | ||
231 | + | ||
214 | $filter = \Yii::$app->request->get('filters', []); | 232 | $filter = \Yii::$app->request->get('filters', []); |
215 | $sort = \Yii::$app->request->get('sort', []); | 233 | $sort = \Yii::$app->request->get('sort', []); |
216 | $paginate = \Yii::$app->request->get('page', []); | 234 | $paginate = \Yii::$app->request->get('page', []); |
217 | 235 | ||
218 | 236 | ||
219 | - | ||
220 | - if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { | 237 | + if (!empty($meta)) { |
221 | 238 | ||
222 | $this->getView()->registerMetaTag([ | 239 | $this->getView()->registerMetaTag([ |
223 | 'name' => 'robots', | 240 | 'name' => 'robots', |
224 | 'content' => $meta | 241 | 'content' => $meta |
225 | ]); | 242 | ]); |
226 | 243 | ||
227 | - } else if(!empty($filter['special'])){ | 244 | + } |
245 | + else if ($widgetData instanceof \common\models\Seo) { | ||
246 | + | ||
247 | + $this->getView()->registerMetaTag([ | ||
248 | + 'name' => 'robots', | ||
249 | + 'content' =>'index,follow' | ||
250 | + ]); | ||
251 | + | ||
252 | + } | ||
253 | + | ||
254 | + else if(!empty($filter['special'])){ | ||
228 | 255 | ||
229 | $this->getView()->registerMetaTag([ | 256 | $this->getView()->registerMetaTag([ |
230 | 'name' => 'robots', | 257 | 'name' => 'robots', |
@@ -232,24 +259,24 @@ class Seo extends Widget | @@ -232,24 +259,24 @@ class Seo extends Widget | ||
232 | ]); | 259 | ]); |
233 | 260 | ||
234 | } else if ( | 261 | } else if ( |
235 | - isset($filter['brands']) && count($filter['brands']) > 1 | ||
236 | - || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices']) | 262 | + isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter) |
237 | 263 | ||
238 | ) { | 264 | ) { |
239 | - | ||
240 | - | ||
241 | $this->getView()->registerMetaTag([ | 265 | $this->getView()->registerMetaTag([ |
242 | 'name' => 'robots', | 266 | 'name' => 'robots', |
243 | 'content' => 'noindex,nofollow' | 267 | 'content' => 'noindex,nofollow' |
244 | ]); | 268 | ]); |
245 | 269 | ||
246 | - } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) { | 270 | + } else if ( |
271 | + isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 | ||
272 | + || isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 | ||
273 | + || !empty($sort) || !empty($paginate) || isset($filter['prices']) | ||
274 | + ) { | ||
247 | $this->getView()->registerMetaTag([ | 275 | $this->getView()->registerMetaTag([ |
248 | 'name' => 'robots', | 276 | 'name' => 'robots', |
249 | 'content' => 'noindex,follow' | 277 | 'content' => 'noindex,follow' |
250 | ]); | 278 | ]); |
251 | - } | ||
252 | - else { | 279 | + } else { |
253 | 280 | ||
254 | $this->getView()->registerMetaTag([ | 281 | $this->getView()->registerMetaTag([ |
255 | 'name' => 'robots', | 282 | 'name' => 'robots', |
@@ -381,93 +408,4 @@ class Seo extends Widget | @@ -381,93 +408,4 @@ class Seo extends Widget | ||
381 | return $fc.mb_substr($str, 1); | 408 | return $fc.mb_substr($str, 1); |
382 | } | 409 | } |
383 | 410 | ||
384 | - public function getDescriptionString($array){ | ||
385 | - // "{Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. по самой лучшей цене с гарантией от производителя - Ruzkachok.com.ua"; | ||
386 | - $row = ''; | ||
387 | - foreach($array as $name => $field){ | ||
388 | - | ||
389 | - if($name == 'category' ){ | ||
390 | - $row = $field.' '.$row; | ||
391 | - } else { | ||
392 | - $row .= $field['name'] .' '.$field['value'].' ' ; | ||
393 | - } | ||
394 | - | ||
395 | - | ||
396 | - | ||
397 | - } | ||
398 | - $row = substr($row, 0,-2 ); | ||
399 | - $row .= " по самой лучшей цене с гарантией от производителя - Rukzachok.com.ua"; | ||
400 | - return $row; | ||
401 | - | ||
402 | - } | ||
403 | - | ||
404 | - | ||
405 | - public function getNameString($array){ | ||
406 | - $row = ''; | ||
407 | - foreach($array as $name => $field){ | ||
408 | - | ||
409 | - if($name == 'category' ){ | ||
410 | - $row = $field.' '.$row; | ||
411 | - } else { | ||
412 | - $row .= $field['name'] .' '.$field['value'].' ' ; | ||
413 | - } | ||
414 | - | ||
415 | - | ||
416 | - | ||
417 | - } | ||
418 | - $row = substr($row, 0,-2 ); | ||
419 | - return $row; | ||
420 | - | ||
421 | - } | ||
422 | - | ||
423 | - public function arrayBuilder($filter) | ||
424 | - { | ||
425 | - | ||
426 | - $array = [ | ||
427 | - 'category' => $this->category_name | ||
428 | - ]; | ||
429 | - | ||
430 | - | ||
431 | - if (isset($filter['brands']) && count($filter['brands']) == 1) { | ||
432 | - $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); | ||
433 | - if (!$model instanceof Brand) { | ||
434 | - | ||
435 | - \Yii::$app->response->redirect(['/site/error'], 404); | ||
436 | - } else { | ||
437 | - $array['brand']['name'] = 'Бренд'; | ||
438 | - $array['brand']['value'] = $model->name; | ||
439 | - } | ||
440 | - | ||
441 | - } | ||
442 | - | ||
443 | - | ||
444 | - $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); | ||
445 | - | ||
446 | - | ||
447 | - foreach ($optionsList as $optionList => $name) { | ||
448 | - | ||
449 | - | ||
450 | - if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { | ||
451 | - | ||
452 | - $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); | ||
453 | - if (!$model instanceof TaxOption) { | ||
454 | - | ||
455 | - \Yii::$app->response->redirect(['site/error'], 404); | ||
456 | - } else { | ||
457 | - $array[$optionList]['value'] = $model->value; | ||
458 | - $array[$optionList]['name'] = $name; | ||
459 | - } | ||
460 | - | ||
461 | - | ||
462 | - } | ||
463 | - | ||
464 | - | ||
465 | - } | ||
466 | - | ||
467 | - return $array; | ||
468 | - | ||
469 | - } | ||
470 | - | ||
471 | - | ||
472 | - | ||
473 | } | 411 | } |
474 | \ No newline at end of file | 412 | \ No newline at end of file |