Commit 9fa9adf7948489cc2e4d6736ee22715ef9296710

Authored by Administrator
1 parent 132aac99

14.09.16

Showing 1 changed file with 118 additions and 28 deletions   Show diff stats
frontend/widgets/Seo.php
... ... @@ -56,7 +56,7 @@ class Seo extends Widget
56 56 foreach ($seoData as $key => $value) {
57 57 $this->$key = $value;
58 58 }
59   -
  59 +
60 60  
61 61 switch ($this->row) {
62 62 case self::SEO_TEXT:
... ... @@ -124,7 +124,7 @@ class Seo extends Widget
124 124  
125 125 } else if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) {
126 126  
127   - $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one();
  127 + $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one();
128 128 if(!$model instanceof TaxOption){
129 129  
130 130 \Yii::$app->response->redirect(['/site/error'],404);
... ... @@ -145,7 +145,7 @@ class Seo extends Widget
145 145 } else {
146 146 return $this->selectSeoData(self::H1);
147 147 }
148   - break;
  148 + break;
149 149 case self::TITLE:
150 150  
151 151 $filter = \Yii::$app->request->get('filters', []);
... ... @@ -220,6 +220,18 @@ class Seo extends Widget
220 220 'content' => $description
221 221 ]);
222 222  
  223 + } else {
  224 +
  225 + $filter = \Yii::$app->request->get('filters', []);
  226 +
  227 + if(!empty($filter)){
  228 + $array = $this->arrayBuilder($filter);
  229 + $this->getView()->registerMetaTag([
  230 + 'name' => 'description',
  231 + 'content' => $this->getDescriptionString($array)
  232 + ]);
  233 + }
  234 +
223 235 }
224 236  
225 237 break;
... ... @@ -227,31 +239,20 @@ class Seo extends Widget
227 239  
228 240 $meta = $this->selectSeoData(self::META);
229 241  
230   - $widgetData = static::findSeoByUrl($this->url);
231   -
232 242 $filter = \Yii::$app->request->get('filters', []);
233 243 $sort = \Yii::$app->request->get('sort', []);
234 244 $paginate = \Yii::$app->request->get('page', []);
235 245  
236 246  
237   - if (!empty($meta)) {
238 247  
239   - $this->getView()->registerMetaTag([
240   - 'name' => 'robots',
241   - 'content' => $meta
242   - ]);
243   -
244   - }
245   - else if ($widgetData instanceof \common\models\Seo) {
  248 + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) {
246 249  
247 250 $this->getView()->registerMetaTag([
248 251 'name' => 'robots',
249   - 'content' =>'index,follow'
  252 + 'content' => $meta
250 253 ]);
251 254  
252   - }
253   -
254   - else if(!empty($filter['special'])){
  255 + } else if(!empty($filter['special'])){
255 256  
256 257 $this->getView()->registerMetaTag([
257 258 'name' => 'robots',
... ... @@ -259,24 +260,24 @@ class Seo extends Widget
259 260 ]);
260 261  
261 262 } else if (
262   - isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter)
  263 + isset($filter['brands']) && count($filter['brands']) > 1
  264 + || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices'])
263 265  
264 266 ) {
  267 +
  268 +
265 269 $this->getView()->registerMetaTag([
266 270 'name' => 'robots',
267 271 'content' => 'noindex,nofollow'
268 272 ]);
269 273  
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   - ) {
  274 + } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) {
275 275 $this->getView()->registerMetaTag([
276 276 'name' => 'robots',
277 277 'content' => 'noindex,follow'
278 278 ]);
279   - } else {
  279 + }
  280 + else {
280 281  
281 282 $this->getView()->registerMetaTag([
282 283 'name' => 'robots',
... ... @@ -363,18 +364,18 @@ class Seo extends Widget
363 364 $result = '';
364 365  
365 366 $widgetData = static::findSeoByUrl($this->url);
366   -
  367 +
367 368 if ($widgetData instanceof \common\models\Seo) {
368 369  
369 370 $result = $widgetData->$param;
370 371  
371 372 } else if (!empty($this->$param)) {
372 373 $result = $this->$param;
373   -
  374 +
374 375 } else {
375 376  
376 377 $widgetData = $this->findSeoByDynamic();
377   -
  378 +
378 379 if ($widgetData instanceof SeoDynamic) {
379 380  
380 381 $result = $widgetData->$param;
... ... @@ -401,11 +402,100 @@ class Seo extends Widget
401 402 return false;
402 403  
403 404 }
404   -
  405 +
405 406 public function my_mb_ucfirst($str) {
406 407 $str = strtolower($str);
407 408 $fc = mb_strtoupper(mb_substr($str, 0, 1));
408 409 return $fc.mb_substr($str, 1);
409 410 }
410 411  
  412 + public function getDescriptionString($array){
  413 + // "{Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. по самой лучшей цене с гарантией от производителя - Ruzkachok.com.ua";
  414 + $row = '';
  415 + foreach($array as $name => $field){
  416 +
  417 + if($name == 'category' ){
  418 + $row = $field.' '.$row;
  419 + } else {
  420 + $row .= $field['name'] .' '.$field['value'].' ' ;
  421 + }
  422 +
  423 +
  424 +
  425 + }
  426 + $row = substr($row, 0,-2 );
  427 + $row .= " по самой лучшей цене с гарантией от производителя - Ruzkachok.com.ua";
  428 + return $row;
  429 +
  430 + }
  431 +
  432 +
  433 + public function getNameString($array){
  434 + $row = '';
  435 + foreach($array as $name => $field){
  436 +
  437 + if($name == 'category' ){
  438 + $row = $field.' '.$row;
  439 + } else {
  440 + $row .= $field['name'] .' '.$field['value'].' ' ;
  441 + }
  442 +
  443 +
  444 +
  445 + }
  446 + $row = substr($row, 0,-2 );
  447 + return $row;
  448 +
  449 + }
  450 +
  451 + public function arrayBuilder($filter)
  452 + {
  453 +
  454 + $array = [
  455 + 'category' => $this->category_name
  456 + ];
  457 +
  458 +
  459 + if (isset($filter['brands']) && count($filter['brands']) == 1) {
  460 + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one();
  461 + if (!$model instanceof Brand) {
  462 +
  463 + \Yii::$app->response->redirect(['/site/error'], 404);
  464 + } else {
  465 + $array['brand']['name'] = 'Бренд';
  466 + $array['brand']['value'] = $model->name;
  467 + }
  468 +
  469 + }
  470 +
  471 +
  472 + $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name');
  473 +
  474 +
  475 + foreach ($optionsList as $optionList => $name) {
  476 +
  477 +
  478 + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) {
  479 +
  480 + $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one();
  481 + if (!$model instanceof TaxOption) {
  482 +
  483 + \Yii::$app->response->redirect(['site/error'], 404);
  484 + } else {
  485 + $array[$optionList]['value'] = $model->value;
  486 + $array[$optionList]['name'] = $name;
  487 + }
  488 +
  489 +
  490 + }
  491 +
  492 +
  493 + }
  494 +
  495 + return $array;
  496 +
  497 + }
  498 +
  499 +
  500 +
411 501 }
412 502 \ No newline at end of file
... ...