Commit 30d2133cee84456c3cc9394afa6bf0c5e0beb687
1 parent
bf6de24b
add variantSku
Showing
4 changed files
with
56 additions
and
98 deletions
Show diff stats
models/SeoDynamicLang.php
@@ -48,7 +48,6 @@ | @@ -48,7 +48,6 @@ | ||
48 | return [ | 48 | return [ |
49 | [ | 49 | [ |
50 | [ | 50 | [ |
51 | - 'meta_title', | ||
52 | 'meta_description', | 51 | 'meta_description', |
53 | 'seo_text', | 52 | 'seo_text', |
54 | ], | 53 | ], |
@@ -101,8 +100,7 @@ | @@ -101,8 +100,7 @@ | ||
101 | return [ | 100 | return [ |
102 | 'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'), | 101 | 'seo_dynamic_id' => Yii::t('app', 'seo_dynamic_id'), |
103 | 'language_id' => Yii::t('app', 'language_id'), | 102 | 'language_id' => Yii::t('app', 'language_id'), |
104 | - 'title' => 'name', | ||
105 | - 'meta_title' => 'title', | 103 | + 'title' => 'title', |
106 | 'h1' => 'h1', | 104 | 'h1' => 'h1', |
107 | 'key' => 'key', | 105 | 'key' => 'key', |
108 | 'meta' => 'meta', | 106 | 'meta' => 'meta', |
views/seo-dynamic/_form_language.php
@@ -17,9 +17,6 @@ | @@ -17,9 +17,6 @@ | ||
17 | <?= $form->field($model_lang, '[' . $language->id . ']title') | 17 | <?= $form->field($model_lang, '[' . $language->id . ']title') |
18 | ->textInput([ 'maxlength' => true ]); ?> | 18 | ->textInput([ 'maxlength' => true ]); ?> |
19 | 19 | ||
20 | -<?= $form->field($model_lang, '[' . $language->id . ']meta_title') | ||
21 | - ->textInput(); ?> | ||
22 | - | ||
23 | <?= $form->field($model_lang, '[' . $language->id . ']meta_description')->textarea() ?> | 20 | <?= $form->field($model_lang, '[' . $language->id . ']meta_description')->textarea() ?> |
24 | 21 | ||
25 | <?= $form->field($model_lang, '[' . $language->id . ']key') | 22 | <?= $form->field($model_lang, '[' . $language->id . ']key') |
views/seo-dynamic/index.php
@@ -47,10 +47,6 @@ | @@ -47,10 +47,6 @@ | ||
47 | 'columns' => [ | 47 | 'columns' => [ |
48 | [ 'class' => 'yii\grid\SerialColumn' ], | 48 | [ 'class' => 'yii\grid\SerialColumn' ], |
49 | 'id', | 49 | 'id', |
50 | - [ | ||
51 | - 'attribute' => 'title', | ||
52 | - 'value' => 'lang.title', | ||
53 | - ], | ||
54 | 'action', | 50 | 'action', |
55 | 'fields', | 51 | 'fields', |
56 | 'param', | 52 | 'param', |
widgets/Seo.php
@@ -66,7 +66,7 @@ class Seo extends Widget | @@ -66,7 +66,7 @@ class Seo extends Widget | ||
66 | 66 | ||
67 | if(empty($filter) && empty($sort) && empty($paginate) ){ | 67 | if(empty($filter) && empty($sort) && empty($paginate) ){ |
68 | 68 | ||
69 | - return $this->selectSeoData(self::SEO_TEXT); | 69 | + return $this->prepareString($this->selectSeoData(self::SEO_TEXT)); |
70 | 70 | ||
71 | } else { | 71 | } else { |
72 | 72 | ||
@@ -84,13 +84,13 @@ class Seo extends Widget | @@ -84,13 +84,13 @@ class Seo extends Widget | ||
84 | 84 | ||
85 | if ($widgetData instanceof SeoDynamic) { | 85 | if ($widgetData instanceof SeoDynamic) { |
86 | 86 | ||
87 | - $result = $widgetData->{self::SEO_TEXT}; | 87 | + $result = $widgetData->lang->{self::SEO_TEXT}; |
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | } | 91 | } |
92 | 92 | ||
93 | - return $this->replaceData($result); | 93 | + return $this->prepareString($this->replaceData($result)); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
@@ -103,18 +103,18 @@ class Seo extends Widget | @@ -103,18 +103,18 @@ class Seo extends Widget | ||
103 | 103 | ||
104 | if ($default != $this->{self::H1}) { | 104 | if ($default != $this->{self::H1}) { |
105 | 105 | ||
106 | - return $default; | 106 | + return $this->prepareString($default); |
107 | 107 | ||
108 | 108 | ||
109 | } else if(!empty($filter) && !$this->checkFilter($filter)){ | 109 | } else if(!empty($filter) && !$this->checkFilter($filter)){ |
110 | $array = $this->arrayBuilder($filter); | 110 | $array = $this->arrayBuilder($filter); |
111 | - return $this->getNameString($array); | 111 | + return $this->prepareString($this->getNameString($array,$default)); |
112 | } | 112 | } |
113 | else { | 113 | else { |
114 | 114 | ||
115 | - return $default; | 115 | + return $this->prepareString($default); |
116 | } | 116 | } |
117 | - break; | 117 | + break; |
118 | case self::TITLE: | 118 | case self::TITLE: |
119 | 119 | ||
120 | $filter = \Yii::$app->request->get('filters', []); | 120 | $filter = \Yii::$app->request->get('filters', []); |
@@ -122,25 +122,23 @@ class Seo extends Widget | @@ -122,25 +122,23 @@ class Seo extends Widget | ||
122 | 122 | ||
123 | $title = $this->selectSeoData(self::TITLE); | 123 | $title = $this->selectSeoData(self::TITLE); |
124 | 124 | ||
125 | - | ||
126 | - if(!empty($filter) && $title == $this->title || !empty($filter) && empty($title)) { | 125 | + if(!empty($filter) && $title == $this->{Seo::TITLE} || !empty($filter) && empty($this->{Seo::TITLE})) { |
127 | 126 | ||
128 | $array = $this->arrayBuilder($filter); | 127 | $array = $this->arrayBuilder($filter); |
129 | 128 | ||
130 | - $title_string = $this->getTitleString($array); | 129 | + $title_string = $this->getTitleString($array, $title); |
131 | 130 | ||
132 | if($title_string){ | 131 | if($title_string){ |
133 | - return $title_string; | 132 | + return $this->prepareString($title_string); |
134 | } | 133 | } |
135 | 134 | ||
136 | } | 135 | } |
137 | 136 | ||
138 | 137 | ||
139 | if (!empty($title)) { | 138 | if (!empty($title)) { |
140 | - | ||
141 | - return $title; | 139 | + return $this->prepareString($title); |
142 | } else { | 140 | } else { |
143 | - return $this->project_name; | 141 | + return $this->prepareString($this->project_name); |
144 | } | 142 | } |
145 | 143 | ||
146 | break; | 144 | break; |
@@ -151,7 +149,7 @@ class Seo extends Widget | @@ -151,7 +149,7 @@ class Seo extends Widget | ||
151 | 149 | ||
152 | $this->getView()->registerMetaTag([ | 150 | $this->getView()->registerMetaTag([ |
153 | 'name' => 'description', | 151 | 'name' => 'description', |
154 | - 'content' => $description | 152 | + 'content' => $this->prepareString($description) |
155 | ]); | 153 | ]); |
156 | 154 | ||
157 | } else { | 155 | } else { |
@@ -162,7 +160,7 @@ class Seo extends Widget | @@ -162,7 +160,7 @@ class Seo extends Widget | ||
162 | $array = $this->arrayBuilder($filter); | 160 | $array = $this->arrayBuilder($filter); |
163 | $this->getView()->registerMetaTag([ | 161 | $this->getView()->registerMetaTag([ |
164 | 'name' => 'description', | 162 | 'name' => 'description', |
165 | - 'content' => $this->getDescriptionString($array) | 163 | + 'content' => $this->prepareString($this->getDescriptionString($array,$description)) |
166 | ]); | 164 | ]); |
167 | } | 165 | } |
168 | 166 | ||
@@ -205,8 +203,8 @@ class Seo extends Widget | @@ -205,8 +203,8 @@ class Seo extends Widget | ||
205 | ]); | 203 | ]); |
206 | 204 | ||
207 | } else if ( | 205 | } else if ( |
208 | - isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 4 | ||
209 | - || isset($filter) && count($filter, COUNT_RECURSIVE) > 4 | 206 | + isset($filter['brands']) && count($filter['brands']) > 1 && isset($filter) && count($filter, COUNT_RECURSIVE) >= 2 |
207 | + || isset($filter) && count($filter, COUNT_RECURSIVE) > 2 | ||
210 | || !empty($sort) || !empty($paginate) || isset($filter['prices']) | 208 | || !empty($sort) || !empty($paginate) || isset($filter['prices']) |
211 | ) { | 209 | ) { |
212 | 210 | ||
@@ -254,9 +252,7 @@ class Seo extends Widget | @@ -254,9 +252,7 @@ class Seo extends Widget | ||
254 | 252 | ||
255 | protected function findSeoByDynamic() | 253 | protected function findSeoByDynamic() |
256 | { | 254 | { |
257 | -// print_r(\Yii::$app->controller->id); | ||
258 | -// print_r(\Yii::$app->controller->action->id); | ||
259 | -// die(); | 255 | + |
260 | if(!empty($this->key)){ | 256 | if(!empty($this->key)){ |
261 | 257 | ||
262 | $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); | 258 | $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); |
@@ -297,110 +293,71 @@ class Seo extends Widget | @@ -297,110 +293,71 @@ class Seo extends Widget | ||
297 | 293 | ||
298 | $widgetData = static::findSeoByUrl($this->url); | 294 | $widgetData = static::findSeoByUrl($this->url); |
299 | 295 | ||
296 | + $widgetDynamicData = $this->findSeoByDynamic(); | ||
297 | + | ||
300 | if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { | 298 | if ($widgetData instanceof \artweb\artbox\seo\models\Seo) { |
301 | 299 | ||
302 | $result = $widgetData->$param; | 300 | $result = $widgetData->$param; |
303 | 301 | ||
304 | - } else if (!empty($this->$param)) { | ||
305 | - $widgetData = $this->findSeoByDynamic(); | ||
306 | - | ||
307 | - if ($widgetData instanceof SeoDynamic) { | 302 | + } else if ($widgetDynamicData instanceof SeoDynamic) { |
308 | 303 | ||
309 | - $result = $widgetData->lang->$param; | ||
310 | - | ||
311 | - } | ||
312 | - | ||
313 | - } else { | 304 | + $result = $widgetDynamicData->lang->$param; |
314 | 305 | ||
306 | + } else if(!empty($this->$param)) { | ||
315 | $result = $this->$param; | 307 | $result = $this->$param; |
316 | - | ||
317 | - | ||
318 | - | ||
319 | } | 308 | } |
320 | 309 | ||
321 | return $this->replaceData($result); | 310 | return $this->replaceData($result); |
322 | 311 | ||
323 | } | 312 | } |
324 | 313 | ||
325 | - public function getTitleString($array){ | ||
326 | - // "{Название раздела: Название блока фильтра | Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3} - купить в Киеве, Украине - интернет магазин Лінія Світла"; | 314 | + public function getTitleString($array, $title){ |
315 | + | ||
327 | $row = ''; | 316 | $row = ''; |
328 | foreach($array as $name => $field){ | 317 | foreach($array as $name => $field){ |
318 | + $row .= $field['name'] .' '.$field['value'].' ' ; | ||
319 | + } | ||
329 | 320 | ||
330 | - if($name == 'category' ){ | ||
331 | - $row = $field.' | '.$row; | ||
332 | - } else { | ||
333 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | ||
334 | - } | ||
335 | - | ||
336 | - | 321 | + $template = preg_replace('/{filter}/',$row,$title); |
337 | 322 | ||
338 | - } | ||
339 | - $row = substr($row, 0,-2 ); | ||
340 | - $row .= " - купить в Киеве, Украине - интернет магазин Екстрим стайл"; | ||
341 | - return $row; | ||
342 | -// $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); | ||
343 | -// if($template instanceof SeoDynamic){ | ||
344 | -// foreach ($array as $field_name => $field_value) { | ||
345 | -// $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); | ||
346 | -// } | ||
347 | -// $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); | ||
348 | -// return $template; | ||
349 | -// } | ||
350 | -// | ||
351 | -// return false; | 323 | + return $template; |
352 | 324 | ||
353 | } | 325 | } |
354 | 326 | ||
355 | 327 | ||
356 | - public function getDescriptionString($array){ | ||
357 | - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | ||
358 | - $row = 'Лучшие цены на '; | ||
359 | - foreach($array as $name => $field){ | ||
360 | - | ||
361 | - if($name == 'category' ){ | ||
362 | - $row = $field.' | '.$row; | ||
363 | - } else { | ||
364 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | ||
365 | - } | 328 | + public function getDescriptionString($array, $description){ |
366 | 329 | ||
330 | + $row = ''; | ||
331 | + foreach($array as $name => $field){ | ||
332 | + $row .= $field['name'] .' '.$field['value'].' ' ; | ||
333 | + } | ||
367 | 334 | ||
335 | + $template = preg_replace('/{filter}/',$row,$title); | ||
368 | 336 | ||
369 | - } | ||
370 | - $row = substr($row, 0,-2 ); | ||
371 | - $row .= ". Екстрим стайл"; | ||
372 | - return $row; | 337 | + return $template; |
373 | 338 | ||
374 | } | 339 | } |
375 | 340 | ||
376 | 341 | ||
377 | - public function getNameString($array){ | ||
378 | - // "Лучшие цены на {Название раздела | Название блока фильтра: Фильтр 1 | Название блока фильтра: Фильтр 2 | Название блока фильтра: Фильтр 3}. Лінія Світла"; | 342 | + public function getNameString($array, $h1){ |
343 | + | ||
379 | $row = ''; | 344 | $row = ''; |
380 | foreach($array as $name => $field){ | 345 | foreach($array as $name => $field){ |
346 | + $row .= $field['name'] .' '.$field['value'].' ' ; | ||
347 | + } | ||
381 | 348 | ||
382 | - if($name == 'category' ){ | ||
383 | - $row = $field.' | '.$row; | ||
384 | - } else { | ||
385 | - $row .= $field['name'] .' '.$field['value'].' | ' ; | ||
386 | - } | ||
387 | - | 349 | + $template = preg_replace('/{filter}/',$row,$title); |
388 | 350 | ||
389 | - | ||
390 | - } | ||
391 | - $row = substr($row, 0,-2 ); | ||
392 | - return $row; | 351 | + return $template; |
393 | 352 | ||
394 | } | 353 | } |
395 | 354 | ||
355 | + /** | ||
356 | + * @param $filter | ||
357 | + * @return mixed | ||
358 | + */ | ||
396 | public function arrayBuilder($filter) | 359 | public function arrayBuilder($filter) |
397 | { | 360 | { |
398 | - | ||
399 | - $array = [ | ||
400 | - 'category' => $this->category_name | ||
401 | - ]; | ||
402 | - | ||
403 | - | ||
404 | if (isset($filter['brands']) && count($filter['brands']) == 1) { | 361 | if (isset($filter['brands']) && count($filter['brands']) == 1) { |
405 | $model = Brand::find()->joinWith('lang')->where(['alias' => $filter['brands'][0]])->one(); | 362 | $model = Brand::find()->joinWith('lang')->where(['alias' => $filter['brands'][0]])->one(); |
406 | if (!$model instanceof Brand) { | 363 | if (!$model instanceof Brand) { |
@@ -441,6 +398,10 @@ class Seo extends Widget | @@ -441,6 +398,10 @@ class Seo extends Widget | ||
441 | 398 | ||
442 | } | 399 | } |
443 | 400 | ||
401 | + /** | ||
402 | + * @param $filter | ||
403 | + * @return bool | ||
404 | + */ | ||
444 | protected function checkFilter($filter){ | 405 | protected function checkFilter($filter){ |
445 | foreach(self::$optionsList as $optionList){ | 406 | foreach(self::$optionsList as $optionList){ |
446 | 407 | ||
@@ -452,5 +413,11 @@ class Seo extends Widget | @@ -452,5 +413,11 @@ class Seo extends Widget | ||
452 | return false; | 413 | return false; |
453 | } | 414 | } |
454 | 415 | ||
416 | + /** | ||
417 | + * @param $string | ||
418 | + */ | ||
419 | + public function prepareString($string){ | ||
420 | + return preg_replace('/\{.[^\}]*\}/','',$string); | ||
421 | + } | ||
455 | 422 | ||
456 | } | 423 | } |
457 | \ No newline at end of file | 424 | \ No newline at end of file |