Commit d84107088245f569503b9bfbd4bfbcc8bf554b3a

Authored by Administrator
1 parent ea07e7cb

14.09.16

frontend/controllers/SiteController.php
... ... @@ -9,9 +9,7 @@ use common\modules\product\models\ProductVariant;
9 9 use Yii;
10 10 use yii\web\Controller;
11 11 use common\models\Page;
12   -use common\models\News;
13   -use common\models\Catalog;
14   -use common\models\Products;
  12 +
15 13  
16 14 class SiteController extends Controller
17 15 {
... ...
frontend/widgets/Seo.php
... ... @@ -101,49 +101,21 @@ class Seo extends Widget
101 101  
102 102 $filter = \Yii::$app->request->get('filters', []);
103 103  
  104 + $default = $this->selectSeoData(self::H1);
104 105  
  106 + if ($default != $this->{self::H1}) {
105 107  
106   - if (isset($filter['brands']) && count($filter['brands']) == 1) {
  108 + return $default;
107 109  
108   - $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one();
109   - if(!$model instanceof Brand){
110   -
111   - \Yii::$app->response->redirect(['/site/error'],404);
112   - } else {
113   - if($this->selectSeoData(self::H1) == $this->category_name) {
114   -
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) {
133   -
134   - return $this->selectSeoData(self::H1) . ' ' . $model->value->value;
135   - }else {
136   -
137   - return $this->selectSeoData(self::H1);
138   -
139   - }
140   -
141   - }
142 110  
  111 + } else if(!empty($filter) && !$this->checkFilter($filter)){
143 112  
  113 + $array = $this->arrayBuilder($filter);
  114 + return $this->getNameString($array);
  115 + }
  116 + else {
144 117  
145   - } else {
146   - return $this->selectSeoData(self::H1);
  118 + return $default;
147 119 }
148 120 break;
149 121 case self::TITLE:
... ... @@ -220,6 +192,18 @@ class Seo extends Widget
220 192 'content' => $description
221 193 ]);
222 194  
  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 +
223 207 }
224 208  
225 209 break;
... ... @@ -227,31 +211,20 @@ class Seo extends Widget
227 211  
228 212 $meta = $this->selectSeoData(self::META);
229 213  
230   - $widgetData = static::findSeoByUrl($this->url);
231   -
232 214 $filter = \Yii::$app->request->get('filters', []);
233 215 $sort = \Yii::$app->request->get('sort', []);
234 216 $paginate = \Yii::$app->request->get('page', []);
235 217  
236 218  
237   - if (!empty($meta)) {
238   -
239   - $this->getView()->registerMetaTag([
240   - 'name' => 'robots',
241   - 'content' => $meta
242   - ]);
243 219  
244   - }
245   - else if ($widgetData instanceof \common\models\Seo) {
  220 + if (!empty($meta) && empty($sort) && empty($paginate) && !isset($filter['prices']) ) {
246 221  
247 222 $this->getView()->registerMetaTag([
248 223 'name' => 'robots',
249   - 'content' =>'index,follow'
  224 + 'content' => $meta
250 225 ]);
251 226  
252   - }
253   -
254   - else if(!empty($filter['special'])){
  227 + } else if(!empty($filter['special'])){
255 228  
256 229 $this->getView()->registerMetaTag([
257 230 'name' => 'robots',
... ... @@ -259,24 +232,24 @@ class Seo extends Widget
259 232 ]);
260 233  
261 234 } else if (
262   - isset($filter['brands']) && count($filter['brands']) > 1 || isset($filter) && $this->checkFilter($filter)
  235 + isset($filter['brands']) && count($filter['brands']) > 1
  236 + || isset($filter) && $this->checkFilter($filter)|| !empty($sort) || !empty($paginate) || isset($filter['prices'])
263 237  
264 238 ) {
  239 +
  240 +
265 241 $this->getView()->registerMetaTag([
266 242 'name' => 'robots',
267 243 'content' => 'noindex,nofollow'
268 244 ]);
269 245  
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   - ) {
  246 + } else if ( isset($filter) && count($filter, COUNT_RECURSIVE) > 4) {
275 247 $this->getView()->registerMetaTag([
276 248 'name' => 'robots',
277 249 'content' => 'noindex,follow'
278 250 ]);
279   - } else {
  251 + }
  252 + else {
280 253  
281 254 $this->getView()->registerMetaTag([
282 255 'name' => 'robots',
... ... @@ -408,4 +381,93 @@ class Seo extends Widget
408 381 return $fc.mb_substr($str, 1);
409 382 }
410 383  
  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 +
411 473 }
412 474 \ No newline at end of file
... ...