Commit 1f3add0ac359899d0f5f53c76112a256c76c7d1e
1 parent
f92291b8
All seo
Showing
14 changed files
with
120 additions
and
33 deletions
Show diff stats
backend/controllers/SeoCategoryController.php
backend/controllers/SeoController.php
backend/controllers/SeoDynamicController.php
backend/views/seo-dynamic/_form.php
... | ... | @@ -7,7 +7,11 @@ use yii\widgets\ActiveForm; |
7 | 7 | /* @var $model common\models\SeoDynamic */ |
8 | 8 | /* @var $form yii\widgets\ActiveForm */ |
9 | 9 | ?> |
10 | - | |
10 | +<style> | |
11 | + #seodynamic-filter_mod { | |
12 | + display: none; | |
13 | + } | |
14 | +</style> | |
11 | 15 | <div class="seo-dynamic-form"> |
12 | 16 | |
13 | 17 | <?php $form = ActiveForm::begin(); ?> |
... | ... | @@ -18,12 +22,27 @@ use yii\widgets\ActiveForm; |
18 | 22 | |
19 | 23 | <?= $form->field($model, 'param')->textInput(['maxlength' => true]) ?> |
20 | 24 | |
25 | + <!-- --><?//= $form->field($model, 'param')->dropDownList([ | |
26 | +// 'filter' => 'filter' | |
27 | +// ],[ 'prompt' => 'Выберите параметр...']); ?> | |
28 | +<!-- <div>--> | |
29 | +<!-- --><?//= | |
30 | +// $form->field($model, 'filter_mod') | |
31 | +// ->radioList( | |
32 | +// ['onefilter' => 'One filter', 'twofilters' => 'Two filters', 'brand_assigment' => 'Brand and assignment '] | |
33 | +// ) | |
34 | +// ->label(false); | |
35 | +// ?> | |
36 | +<!-- </div>--> | |
37 | + | |
21 | 38 | <?= $form->field($model, 'key')->textInput(['maxlength' => true]) ?> |
22 | 39 | |
23 | 40 | <?= $form->field($model, 'fields')->textInput(['maxlength' => true]) ?> |
24 | 41 | |
25 | 42 | <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> |
26 | 43 | |
44 | + <?= $form->field($model, 'meta')->textInput(['maxlength' => true]) ?> | |
45 | + | |
27 | 46 | <?= $form->field($model, 'h1')->textInput(['maxlength' => true]) ?> |
28 | 47 | |
29 | 48 | <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?> |
... | ... | @@ -37,5 +56,17 @@ use yii\widgets\ActiveForm; |
37 | 56 | </div> |
38 | 57 | |
39 | 58 | <?php ActiveForm::end(); ?> |
40 | - | |
59 | +<!--<script>--> | |
60 | +<!-- $('#seodynamic-param').on('change',function(){--> | |
61 | +<!----> | |
62 | +<!-- if($(this).val() == 'filter') {--> | |
63 | +<!-- $('#seodynamic-filter_mod').show();--> | |
64 | +<!-- alert('ok');--> | |
65 | +<!-- } else {--> | |
66 | +<!----> | |
67 | +<!-- $('#seodynamic-filter_mod').hide();--> | |
68 | +<!-- }--> | |
69 | +<!-- });--> | |
70 | +<!----> | |
71 | +<!--</script>--> | |
41 | 72 | </div> | ... | ... |
backend/views/seo-dynamic/index.php
backend/views/seo-dynamic/view.php
common/models/SeoDynamic.php
... | ... | @@ -41,7 +41,7 @@ class SeoDynamic extends \yii\db\ActiveRecord |
41 | 41 | [['seo_category_id', 'status'], 'integer'], |
42 | 42 | [['seo_text'], 'string'], |
43 | 43 | [['name', 'action'], 'string', 'max' => 200], |
44 | - [['fields', 'title', 'h1', 'description', 'param', 'key'], 'string', 'max' => 255], | |
44 | + [['fields', 'title', 'meta', 'h1', 'description', 'param', 'key'], 'string', 'max' => 255], | |
45 | 45 | [['seo_category_id'], 'exist', 'skipOnError' => true, 'targetClass' => SeoCategory::className(), 'targetAttribute' => ['seo_category_id' => 'seo_category_id']], |
46 | 46 | ]; |
47 | 47 | } |
... | ... | @@ -58,6 +58,7 @@ class SeoDynamic extends \yii\db\ActiveRecord |
58 | 58 | 'action' => Yii::t('app', 'action'), |
59 | 59 | 'fields' => Yii::t('app', 'fields'), |
60 | 60 | 'title' => Yii::t('app', 'title'), |
61 | + 'meta' => Yii::t('app', 'meta'), | |
61 | 62 | 'h1' => Yii::t('app', 'h1'), |
62 | 63 | 'description' => Yii::t('app', 'description'), |
63 | 64 | 'seo_text' => Yii::t('app', 'seo_text'), | ... | ... |
common/models/SeoDynamicSearch.php
... | ... | @@ -19,7 +19,7 @@ class SeoDynamicSearch extends SeoDynamic |
19 | 19 | { |
20 | 20 | return [ |
21 | 21 | [['seo_dynamic_id', 'seo_category_id', 'status'], 'integer'], |
22 | - [['name', 'action', 'fields', 'title', 'h1', 'description', 'seo_text'], 'safe'], | |
22 | + [['name', 'action', 'fields', 'title', 'meta', 'h1', 'description', 'seo_text'], 'safe'], | |
23 | 23 | ]; |
24 | 24 | } |
25 | 25 | |
... | ... | @@ -68,6 +68,7 @@ class SeoDynamicSearch extends SeoDynamic |
68 | 68 | ->andFilterWhere(['like', 'action', $this->action]) |
69 | 69 | ->andFilterWhere(['like', 'fields', $this->fields]) |
70 | 70 | ->andFilterWhere(['like', 'title', $this->title]) |
71 | + ->andFilterWhere(['like', 'meta', $this->title]) | |
71 | 72 | ->andFilterWhere(['like', 'h1', $this->h1]) |
72 | 73 | ->andFilterWhere(['like', 'description', $this->description]) |
73 | 74 | ->andFilterWhere(['like', 'seo_text', $this->seo_text]); | ... | ... |
frontend/config/main.php
... | ... | @@ -87,7 +87,7 @@ return [ |
87 | 87 | // 'products/<translit:\w+>' => 'products/index', |
88 | 88 | // 'products/<translit_rubric:\w+>/<translit:[\w\-]+>-<id:\d+>' => 'products/show', |
89 | 89 | 'news/<translit:\w+>-<id:\d+>' => 'news/show', |
90 | - 'brends/<translit:[\w\-]+>' => 'brends/show', | |
90 | + //'brends/<translit:[\w\-]+>' => 'brends/show', | |
91 | 91 | 'brends' => 'brends/index', |
92 | 92 | 'blog' => 'articles/index', |
93 | 93 | 'blog/<translit:[\w\-]+>-<id:\d+>' => 'articles/show', | ... | ... |
frontend/views/brends/show.php
... | ... | @@ -5,7 +5,8 @@ |
5 | 5 | use yii\widgets\LinkPager; |
6 | 6 | use yii\web\View; |
7 | 7 | |
8 | - $this->title = $brend->name; | |
8 | +// $this->title = $brend->name; | |
9 | + $this->params['seo']['fields']['name'] = $brend->name; | |
9 | 10 | $this->registerMetaTag (['name' => 'description', 'content' => $brend->name]); |
10 | 11 | $this->registerMetaTag (['name' => 'keywords', 'content' => $brend->name]); |
11 | 12 | $this->params['breadcrumbs'][] = ['label' => 'Бренды', 'url' => ['/brends/index']]; |
... | ... | @@ -30,11 +31,11 @@ |
30 | 31 | |
31 | 32 | <ul> |
32 | 33 | |
33 | - <?phpforeach ($products as $item): ?> | |
34 | + <?php foreach ($products as $item): ?> | |
34 | 35 | <li class="item"> |
35 | 36 | <?= $this->render ('/products/_product', ['item' => $item, 'num' => 3]) ?> |
36 | 37 | </li> |
37 | - <?phpendforeach; ?> | |
38 | + <?php endforeach; ?> | |
38 | 39 | |
39 | 40 | </ul> |
40 | 41 | <div class="both"></div> | ... | ... |
frontend/views/catalog/brand.php
... | ... | @@ -13,11 +13,7 @@ $this->title = $brand->name; |
13 | 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('products', 'Brands'), 'url' => ['catalog/brands']]; |
14 | 14 | $this->params['breadcrumbs'][] = $brand->name; |
15 | 15 | |
16 | -$this->params['seo']['seo_text'] = 'TEST SEO TEXT'; | |
17 | -$this->params['seo']['h1'] = 'TEST H1'; | |
18 | -$this->params['seo']['description'] = 'TEST DESCRIPTION'; | |
19 | -$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD'; | |
20 | -$this->params['seo']['key']= 'product_list'; | |
16 | +$this->params['seo']['fields']['name'] = $brand->name; | |
21 | 17 | |
22 | 18 | $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.css')); |
23 | 19 | $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.skinHTML5.css')); | ... | ... |
frontend/views/catalog/product.php
... | ... | @@ -2,10 +2,14 @@ |
2 | 2 | use yii\widgets\Breadcrumbs; |
3 | 3 | use yii\web\View; |
4 | 4 | use yii\helpers\Url; |
5 | +use frontend\widgets\Seo; | |
5 | 6 | |
6 | -//$this->params['seo']['title'] = $product->fullname; | |
7 | -$this->params['seo']['title'] = "Купить " . substr($product->category->categoryName->value, 0, -2) . " " . $product->fullname . " в Киеве, Харькове, Украине: цены, отзывы - Rukzachok.com.ua"; | |
8 | -$this->params['seo']['description'] = "Заказать " . substr($product->category->categoryName->value, 0, -2) . " " . $product->fullname . " - самые модные и стильные рюкзаки в Украине по лучшим ценам. Интернет магазин рюкзаков Rukzachok.com.ua"; | |
7 | +$this->params['seo']['key'] = $product->category->categoryName->value; | |
8 | +$this->params['seo']['fields']['name'] = $product->fullname; | |
9 | +$this->params['seo']['h1'] = !empty(Seo::widget([ 'row'=>'h1'])) ? Seo::widget([ 'row'=>'h1']) : $product->fullname; | |
10 | + | |
11 | +//$this->params['seo']['title'] = "Купить " . substr($product->category->categoryName->value, 0, -2) . " " . $product->fullname . " в Киеве, Харькове, Украине: цены, отзывы - Rukzachok.com.ua"; | |
12 | +//$this->params['seo']['description'] = "Заказать " . substr($product->category->categoryName->value, 0, -2) . " " . $product->fullname . " - самые модные и стильные рюкзаки в Украине по лучшим ценам. Интернет магазин рюкзаков Rukzachok.com.ua"; | |
9 | 13 | $this->title = $product->fullname; |
10 | 14 | //$this->title = (! empty($product->meta_title)) ? $product->meta_title : $product->fullname; |
11 | 15 | //$this->registerMetaTag (['name' => 'description', 'content' => ((! empty($product->meta_description)) ? $product->meta_description : $product->fullname)]); |
... | ... | @@ -96,7 +100,7 @@ $this->registerJs (" |
96 | 100 | <?php endif; ?> |
97 | 101 | <div class="loyout"> |
98 | 102 | <div class="productLeftBar"> |
99 | - <h1><?= $product->fullname ?></h1> | |
103 | + <h1><?= Seo::widget([ 'row'=>'h1'])?></h1> | |
100 | 104 | <?php foreach($product->enabledVariantsGrouped as $variantGroup) :?> |
101 | 105 | <div class="begin"><?= $variantGroup->name2?></div> |
102 | 106 | <ul class="product_mod"> | ... | ... |
frontend/views/catalog/products.php
... | ... | @@ -9,12 +9,12 @@ use yii\web\View; |
9 | 9 | use common\modules\product\helpers\ProductHelper; |
10 | 10 | use frontend\widgets\Seo; |
11 | 11 | //$this->title = $category->categoryName->value; |
12 | -$this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : "Купить " . substr($category->name, 0, -2) . " в Украине недорого |" . $category->name . " доставка в Киев, Харьков, Днепропетровск, Одесса - Rukzachok.com.ua"; | |
12 | +//$this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : "Купить " . substr($category->name, 0, -2) . " в Украине недорого |" . $category->name . " доставка в Киев, Харьков, Днепропетровск, Одесса - Rukzachok.com.ua"; | |
13 | 13 | $this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name; |
14 | 14 | $this->params['seo']['seo_text'] = $category->seo_text; |
15 | 15 | $this->params['seo']['description'] = $category->meta_desc; |
16 | 16 | $this->params['seo']['meta'] = $category->meta_robots; |
17 | - | |
17 | +$this->params['seo']['category_name'] = $category->name; | |
18 | 18 | //foreach($category->getParents()->all() as $parent) { |
19 | 19 | // $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]]; |
20 | 20 | //} | ... | ... |
frontend/widgets/Seo.php
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | namespace frontend\widgets; |
3 | 3 | |
4 | 4 | use common\models\SeoDynamic; |
5 | + | |
6 | +use common\modules\product\models\Brand; | |
7 | +use common\modules\rubrication\models\TaxOption; | |
5 | 8 | use yii\base\Widget; |
6 | 9 | use yii\helpers\Html; |
7 | 10 | |
... | ... | @@ -11,12 +14,14 @@ class Seo extends Widget |
11 | 14 | public $row; |
12 | 15 | public $own_attr; |
13 | 16 | public $fields; |
17 | + public $category_name; | |
14 | 18 | public $description; |
15 | 19 | public $title; |
16 | 20 | public $meta; |
17 | 21 | public $seo_text; |
18 | 22 | public $h1; |
19 | 23 | public $key; |
24 | + public $name; | |
20 | 25 | public $project_name; |
21 | 26 | |
22 | 27 | |
... | ... | @@ -75,12 +80,49 @@ class Seo extends Widget |
75 | 80 | // if(!empty($filter_row)){ |
76 | 81 | // return $filter_row; |
77 | 82 | // } |
83 | + | |
78 | 84 | if (!empty($title)) { |
79 | 85 | return $title; |
80 | - } else { | |
81 | - return $this->project_name; | |
82 | 86 | } |
83 | 87 | |
88 | + $array = [ | |
89 | + 'category' => $this->category_name | |
90 | + ]; | |
91 | + | |
92 | + | |
93 | + if (isset($filter['brands']) && count($filter['brands']) == 1 ) | |
94 | + { | |
95 | + $model = Brand::find()->where(['alias' => $filter['brands'][0]])->one(); | |
96 | + | |
97 | + $array['brand'] = $model->name; | |
98 | + } | |
99 | + | |
100 | + if ( isset($filter['options']["pol"]) && count($filter['options']["pol"]) == 1) | |
101 | + { | |
102 | + | |
103 | + $model = TaxOption::find()->where(['alias' => $filter['options']["pol"]])->one(); | |
104 | + $array['sex'] = $model->value->value; | |
105 | + | |
106 | + | |
107 | + } | |
108 | + | |
109 | + if (isset($filter['options']["naznacenie"]) && count($filter['options']["naznacenie"]) == 1){ | |
110 | + | |
111 | + $model = TaxOption::find()->where(['alias' => $filter['options']["naznacenie"]])->one(); | |
112 | + $array['naz'] = $model->value->value; | |
113 | + | |
114 | + } | |
115 | + | |
116 | + if (isset($filter['options']["god"]) && count($filter['options']["god"]) == 1){ | |
117 | + $model = TaxOption::find()->where(['alias' => $filter['options']["god"]])->one(); | |
118 | + $array['year'] = $model->value->value; | |
119 | + | |
120 | + } | |
121 | + return $this->getTitleString($array); | |
122 | +// else { | |
123 | +// return $this->project_name; | |
124 | +// } | |
125 | + | |
84 | 126 | break; |
85 | 127 | case self::DESCRIPTION: |
86 | 128 | $description = $this->selectSeoData(self::DESCRIPTION); |
... | ... | @@ -163,10 +205,15 @@ class Seo extends Widget |
163 | 205 | |
164 | 206 | protected function findSeoByDynamic() |
165 | 207 | { |
166 | - $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); | |
167 | - if (!empty($this->key)) { | |
168 | - $query->andWhere(['key' => $this->key]); | |
208 | + | |
209 | + if(!empty($this->key)){ | |
210 | + | |
211 | + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); | |
212 | + } else { | |
213 | + | |
214 | + $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); | |
169 | 215 | } |
216 | + | |
170 | 217 | return $query->one(); |
171 | 218 | } |
172 | 219 | |
... | ... | @@ -210,5 +257,15 @@ class Seo extends Widget |
210 | 257 | |
211 | 258 | } |
212 | 259 | |
260 | + public function getTitleString($array){ | |
261 | + $template = "{category} {naz} {brand} {sex} {year} купить в Украине, Киев, Харькове - цены, фото, отзывы | Rukzachok.com.ua"; | |
262 | + foreach ($array as $field_name => $field_value) { | |
263 | + $template = str_replace('{' . $field_name . '}', $field_value, $template); | |
264 | + } | |
265 | + $template = preg_replace('/\{.[^\}]*\}\s/','',$template); | |
266 | + return $template; | |
267 | + | |
268 | + } | |
269 | + | |
213 | 270 | |
214 | 271 | } |
215 | 272 | \ No newline at end of file | ... | ... |