Commit 14792485a8f41f2973cb9b70898070beff592f29
1 parent
e0c6eb0a
added SeoProduct component
Showing
4 changed files
with
173 additions
and
4 deletions
Show diff stats
artweb/artbox-core/components/SeoComponent.php
| @@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
| 24 | class SeoComponent extends Object | 24 | class SeoComponent extends Object |
| 25 | { | 25 | { |
| 26 | /** | 26 | /** |
| 27 | - * Read only roperty to show wether Alias was loaded or not | 27 | + * Property to show wether Alias was loaded or not |
| 28 | * | 28 | * |
| 29 | * @var bool | 29 | * @var bool |
| 30 | */ | 30 | */ |
| @@ -81,7 +81,7 @@ | @@ -81,7 +81,7 @@ | ||
| 81 | protected $model; | 81 | protected $model; |
| 82 | 82 | ||
| 83 | /** | 83 | /** |
| 84 | - * Getter for read only property | 84 | + * Getter for protected property |
| 85 | * | 85 | * |
| 86 | * @return bool | 86 | * @return bool |
| 87 | */ | 87 | */ |
| @@ -89,6 +89,17 @@ | @@ -89,6 +89,17 @@ | ||
| 89 | { | 89 | { |
| 90 | return $this->loaded; | 90 | return $this->loaded; |
| 91 | } | 91 | } |
| 92 | + | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Setter for protected property | ||
| 96 | + * | ||
| 97 | + * @return void | ||
| 98 | + */ | ||
| 99 | + public function setLoaded(bool $status) | ||
| 100 | + { | ||
| 101 | + $this->loaded = $status; | ||
| 102 | + } | ||
| 92 | 103 | ||
| 93 | /** | 104 | /** |
| 94 | * Setting alias model | 105 | * Setting alias model |
| @@ -120,6 +131,14 @@ | @@ -120,6 +131,14 @@ | ||
| 120 | { | 131 | { |
| 121 | return $this->alias->getId(); | 132 | return $this->alias->getId(); |
| 122 | } | 133 | } |
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * @return AliasInterface | ||
| 137 | + */ | ||
| 138 | + public function getAlias() | ||
| 139 | + { | ||
| 140 | + return $this->alias; | ||
| 141 | + } | ||
| 123 | 142 | ||
| 124 | /** | 143 | /** |
| 125 | * @return string | 144 | * @return string |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace frontend\components; | ||
| 4 | + | ||
| 5 | +use artbox\core\models\Alias; | ||
| 6 | +use artbox\core\models\interfaces\AliasInterface; | ||
| 7 | +use yii\base\Object; | ||
| 8 | + | ||
| 9 | +class SeoProduct extends Object implements AliasInterface | ||
| 10 | +{ | ||
| 11 | + /** | ||
| 12 | + * @var int | ||
| 13 | + */ | ||
| 14 | + public $languageId; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * @var string | ||
| 18 | + */ | ||
| 19 | + public $productTitle; | ||
| 20 | + | ||
| 21 | + public $productPrice; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * @var string | ||
| 25 | + */ | ||
| 26 | + public $tel = '(044) 490 70 07'; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * @var Alias | ||
| 30 | + */ | ||
| 31 | + public $productAlias; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @var string | ||
| 35 | + */ | ||
| 36 | + protected $title = ''; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @var string | ||
| 40 | + */ | ||
| 41 | + protected $description = ''; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * @var string | ||
| 45 | + */ | ||
| 46 | + protected $h1 = ''; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * @var string | ||
| 50 | + */ | ||
| 51 | + protected $robots = ''; | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * @var string | ||
| 55 | + */ | ||
| 56 | + protected $text = ''; | ||
| 57 | + | ||
| 58 | + public function init() | ||
| 59 | + { | ||
| 60 | + $this->generateData(); | ||
| 61 | + | ||
| 62 | + $this->generateRobots(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public function getFields(): string | ||
| 66 | + { | ||
| 67 | + return ''; | ||
| 68 | + } | ||
| 69 | + public function getSeoText(): string | ||
| 70 | + { | ||
| 71 | + return $this->text ?? ''; | ||
| 72 | + } | ||
| 73 | + public function getId() | ||
| 74 | + { | ||
| 75 | + return 0; | ||
| 76 | + } | ||
| 77 | + public function getTitle(): string | ||
| 78 | + { | ||
| 79 | + return $this->title ?? ''; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public function getDesc(): string | ||
| 83 | + { | ||
| 84 | + return $this->description ?? ''; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public function getH1(): string | ||
| 88 | + { | ||
| 89 | + return $this->h1 ?? ''; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public function getText(): string | ||
| 93 | + { | ||
| 94 | + return $this->text ?? ''; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public function getRobots(): string | ||
| 98 | + { | ||
| 99 | + return $this->robots ?? ''; | ||
| 100 | + } | ||
| 101 | + private function selectH1() | ||
| 102 | + { | ||
| 103 | + if (!empty($this->productAlias->h1)) { | ||
| 104 | + $this->h1 = $this->productAlias->h1; | ||
| 105 | + } else { | ||
| 106 | + $this->h1 = $this->productTitle; | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + protected function selectDescription() { | ||
| 110 | +// if (!empty($this->productAlias->description)) { | ||
| 111 | +// $this->description = $this->productAlias->description; | ||
| 112 | +// } else { | ||
| 113 | + $this->description = 'Купити '.$this->h1.' в інтернет-магазині ACDC | Тільки оригінал > Доступні ціни > Покупка в кредит > Швидка доставка по Україні'; | ||
| 114 | +// } | ||
| 115 | + } | ||
| 116 | + protected function selectTitle() | ||
| 117 | + { | ||
| 118 | +// if (!empty($this->productAlias->title)) { // у всех продуктов задан алиас, пришлось убрать кастомные алиасы, | ||
| 119 | +// $this->title = $this->productAlias->title; // чтобы применить массовые | ||
| 120 | +// } else { | ||
| 121 | + $this->title = $this->h1.' купити в Україні: Київ, Харків, Одесса - ціна, фото, відгуки | інтернет-магазин ACDC'; | ||
| 122 | +// } | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + private function generateData() | ||
| 126 | + { | ||
| 127 | + $this->selectH1(); | ||
| 128 | + $this->selectTitle(); | ||
| 129 | + $this->selectDescription(); | ||
| 130 | + } | ||
| 131 | + private function generateRobots() | ||
| 132 | + { | ||
| 133 | + if(!empty($this->productAlias->robots)) { | ||
| 134 | + $this->robots = $this->productAlias->robots; | ||
| 135 | + } else { | ||
| 136 | + $this->robots = 'index, follow'; | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | +} | ||
| 0 | \ No newline at end of file | 140 | \ No newline at end of file |
frontend/controllers/ProductController.php
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | use artbox\catalog\models\Product; | 4 | use artbox\catalog\models\Product; |
| 5 | use artbox\core\components\SeoComponent; | 5 | use artbox\core\components\SeoComponent; |
| 6 | use artbox\order\models\Wishlist; | 6 | use artbox\order\models\Wishlist; |
| 7 | + use frontend\components\SeoProduct; | ||
| 7 | use yii\db\ActiveQuery; | 8 | use yii\db\ActiveQuery; |
| 8 | use yii\helpers\Html; | 9 | use yii\helpers\Html; |
| 9 | use yii\helpers\Url; | 10 | use yii\helpers\Url; |
| @@ -37,7 +38,17 @@ | @@ -37,7 +38,17 @@ | ||
| 37 | $variant = $model->variants[ 0 ]; | 38 | $variant = $model->variants[ 0 ]; |
| 38 | $groups = $variant->getSortedGroups(); | 39 | $groups = $variant->getSortedGroups(); |
| 39 | $similar = $model->getSimilarProducts(8); | 40 | $similar = $model->getSimilarProducts(8); |
| 40 | - | 41 | + $seoData = new SeoProduct( |
| 42 | + [ | ||
| 43 | + 'productTitle' => $model->lang->title, | ||
| 44 | + 'productPrice' => $variant->price, | ||
| 45 | + 'productAlias' => $seo->alias, | ||
| 46 | + 'languageId' => $model->lang->language_id, | ||
| 47 | + ] | ||
| 48 | + ); | ||
| 49 | + $seo->loaded = false; | ||
| 50 | + $seo->setAlias($seoData); | ||
| 51 | + | ||
| 41 | return $this->render( | 52 | return $this->render( |
| 42 | 'view', | 53 | 'view', |
| 43 | [ | 54 | [ |
frontend/views/product/view.php
| @@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
| 39 | ], | 39 | ], |
| 40 | ]; | 40 | ]; |
| 41 | } | 41 | } |
| 42 | - $this->params[ 'breadcrumbs' ][] = $seo->title; | 42 | + $this->params[ 'breadcrumbs' ][] = $seo->h1; |
| 43 | $images = $model->images; | 43 | $images = $model->images; |
| 44 | if (empty($model->images)) | 44 | if (empty($model->images)) |
| 45 | { | 45 | { |