diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index e8f0ef6..6a56bd1 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -9,9 +9,7 @@ use common\modules\product\models\ProductVariant; use Yii; use yii\web\Controller; use common\models\Page; -use common\models\News; -use common\models\Catalog; -use common\models\Products; + class SiteController extends Controller { diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index b277214..c25bb90 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -101,49 +101,21 @@ class Seo extends Widget $filter = \Yii::$app->request->get('filters', []); + $default = $this->selectSeoData(self::H1); + if ($default != $this->{self::H1}) { - if (isset($filter['brands']) && count($filter['brands']) == 1) { + return $default; - $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); - if(!$model instanceof Brand){ - - \Yii::$app->response->redirect(['/site/error'],404); - } else { - if($this->selectSeoData(self::H1) == $this->category_name) { - - return $this->selectSeoData(self::H1) . ' ' . $model->name ; - }else { - - return $this->selectSeoData(self::H1); - - } - } - - - - } else if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { - - $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); - if(!$model instanceof TaxOption){ - - \Yii::$app->response->redirect(['/site/error'],404); - } else { - if($this->selectSeoData(self::H1) == $this->category_name) { - - return $this->selectSeoData(self::H1) . ' ' . $model->value->value; - }else { - - return $this->selectSeoData(self::H1); - - } - - } + } else if(!empty($filter) && !$this->checkFilter($filter)){ + $array = $this->arrayBuilder($filter); + return $this->getNameString($array); + } + else { - } else { - return $this->selectSeoData(self::H1); + return $default; } break; case self::TITLE: @@ -220,6 +192,18 @@ class Seo extends Widget 'content' => $description ]); + } else { + + $filter = \Yii::$app->request->get('filters', []); + + if(!empty($filter)){ + $array = $this->arrayBuilder($filter); + $this->getView()->registerMetaTag([ + 'name' => 'description', + 'content' => $this->getDescriptionString($array) + ]); + } + } break; @@ -227,31 +211,20 @@ class Seo extends Widget $meta = $this->selectSeoData(self::META); - $widgetData = static::findSeoByUrl($this->url); - $filter = \Yii::$app->request->get('filters', []); $sort = \Yii::$app->request->get('sort', []); $paginate = \Yii::$app->request->get('page', []); - if (!empty($meta)) { - - $this->getView()->registerMetaTag([ - 'name' => 'robots', - 'content' => $meta - ]); - } - else if ($widgetData instanceof \common\models\Seo) { + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) { $this->getView()->registerMetaTag([ 'name' => 'robots', - 'content' =>'index,follow' + 'content' => $meta ]); - } - - else if(!empty($filter['special'])){ + } else if(!empty($filter['special'])){ $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -259,24 +232,24 @@ class Seo extends Widget ]); } else if ( - isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter) + isset($filter['brands']) && count($filter['brands']) > 1 + || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices']) ) { + + $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,nofollow' ]); - } else if ( - isset($filter['brands']) && count($filter['brands']) <= 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 - || isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 - || !empty($sort) || !empty($paginate) || isset($filter['prices']) - ) { + } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) { $this->getView()->registerMetaTag([ 'name' => 'robots', 'content' => 'noindex,follow' ]); - } else { + } + else { $this->getView()->registerMetaTag([ 'name' => 'robots', @@ -408,4 +381,93 @@ class Seo extends Widget return $fc.mb_substr($str, 1); } + public function getDescriptionString($array){ + // "{Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. по самой лучшей цене с гарантией от производителя - Ruzkachok.com.ua"; + $row = ''; + foreach($array as $name => $field){ + + if($name == 'category' ){ + $row = $field.' '.$row; + } else { + $row .= $field['name'] .' '.$field['value'].' ' ; + } + + + + } + $row = substr($row, 0,-2 ); + $row .= " по самой лучшей цене с гарантией от производителя - Rukzachok.com.ua"; + return $row; + + } + + + public function getNameString($array){ + $row = ''; + foreach($array as $name => $field){ + + if($name == 'category' ){ + $row = $field.' '.$row; + } else { + $row .= $field['name'] .' '.$field['value'].' ' ; + } + + + + } + $row = substr($row, 0,-2 ); + return $row; + + } + + public function arrayBuilder($filter) + { + + $array = [ + 'category' => $this->category_name + ]; + + + if (isset($filter['brands']) && count($filter['brands']) == 1) { + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); + if (!$model instanceof Brand) { + + \Yii::$app->response->redirect(['/site/error'], 404); + } else { + $array['brand']['name'] = 'Бренд'; + $array['brand']['value'] = $model->name; + } + + } + + + $optionsList = ArrayHelper::map(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(), 'alias', 'name'); + + + foreach ($optionsList as $optionList => $name) { + + + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { + + $model = TaxOption::find()->where(['alias' => $filter[$optionList]])->one(); + if (!$model instanceof TaxOption) { + + \Yii::$app->response->redirect(['site/error'], 404); + } else { + $array[$optionList]['value'] = $model->value; + $array[$optionList]['name'] = $name; + } + + + } + + + } + + return $array; + + } + + + } \ No newline at end of file -- libgit2 0.21.4