From 14792485a8f41f2973cb9b70898070beff592f29 Mon Sep 17 00:00:00 2001 From: diver90 Date: Tue, 3 Aug 2021 13:05:11 +0300 Subject: [PATCH] added SeoProduct component --- artweb/artbox-core/components/SeoComponent.php | 23 +++++++++++++++++++++-- frontend/components/SeoProduct.php | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/controllers/ProductController.php | 13 ++++++++++++- frontend/views/product/view.php | 2 +- 4 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 frontend/components/SeoProduct.php diff --git a/artweb/artbox-core/components/SeoComponent.php b/artweb/artbox-core/components/SeoComponent.php index 20475cf..6f0d173 100644 --- a/artweb/artbox-core/components/SeoComponent.php +++ b/artweb/artbox-core/components/SeoComponent.php @@ -24,7 +24,7 @@ class SeoComponent extends Object { /** - * Read only roperty to show wether Alias was loaded or not + * Property to show wether Alias was loaded or not * * @var bool */ @@ -81,7 +81,7 @@ protected $model; /** - * Getter for read only property + * Getter for protected property * * @return bool */ @@ -89,6 +89,17 @@ { return $this->loaded; } + + + /** + * Setter for protected property + * + * @return void + */ + public function setLoaded(bool $status) + { + $this->loaded = $status; + } /** * Setting alias model @@ -120,6 +131,14 @@ { return $this->alias->getId(); } + + /** + * @return AliasInterface + */ + public function getAlias() + { + return $this->alias; + } /** * @return string diff --git a/frontend/components/SeoProduct.php b/frontend/components/SeoProduct.php new file mode 100644 index 0000000..9913b3f --- /dev/null +++ b/frontend/components/SeoProduct.php @@ -0,0 +1,139 @@ +generateData(); + + $this->generateRobots(); + } + + public function getFields(): string + { + return ''; + } + public function getSeoText(): string + { + return $this->text ?? ''; + } + public function getId() + { + return 0; + } + public function getTitle(): string + { + return $this->title ?? ''; + } + + public function getDesc(): string + { + return $this->description ?? ''; + } + + public function getH1(): string + { + return $this->h1 ?? ''; + } + + public function getText(): string + { + return $this->text ?? ''; + } + + public function getRobots(): string + { + return $this->robots ?? ''; + } + private function selectH1() + { + if (!empty($this->productAlias->h1)) { + $this->h1 = $this->productAlias->h1; + } else { + $this->h1 = $this->productTitle; + } + } + protected function selectDescription() { +// if (!empty($this->productAlias->description)) { +// $this->description = $this->productAlias->description; +// } else { + $this->description = 'Купити '.$this->h1.' в інтернет-магазині ACDC | Тільки оригінал > Доступні ціни > Покупка в кредит > Швидка доставка по Україні'; +// } + } + protected function selectTitle() + { +// if (!empty($this->productAlias->title)) { // у всех продуктов задан алиас, пришлось убрать кастомные алиасы, +// $this->title = $this->productAlias->title; // чтобы применить массовые +// } else { + $this->title = $this->h1.' купити в Україні: Київ, Харків, Одесса - ціна, фото, відгуки | інтернет-магазин ACDC'; +// } + } + + private function generateData() + { + $this->selectH1(); + $this->selectTitle(); + $this->selectDescription(); + } + private function generateRobots() + { + if(!empty($this->productAlias->robots)) { + $this->robots = $this->productAlias->robots; + } else { + $this->robots = 'index, follow'; + } + } +} \ No newline at end of file diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index 4ce5aa2..f5a5ac2 100755 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -4,6 +4,7 @@ use artbox\catalog\models\Product; use artbox\core\components\SeoComponent; use artbox\order\models\Wishlist; + use frontend\components\SeoProduct; use yii\db\ActiveQuery; use yii\helpers\Html; use yii\helpers\Url; @@ -37,7 +38,17 @@ $variant = $model->variants[ 0 ]; $groups = $variant->getSortedGroups(); $similar = $model->getSimilarProducts(8); - + $seoData = new SeoProduct( + [ + 'productTitle' => $model->lang->title, + 'productPrice' => $variant->price, + 'productAlias' => $seo->alias, + 'languageId' => $model->lang->language_id, + ] + ); + $seo->loaded = false; + $seo->setAlias($seoData); + return $this->render( 'view', [ diff --git a/frontend/views/product/view.php b/frontend/views/product/view.php index 4ae9a35..09ea8a6 100755 --- a/frontend/views/product/view.php +++ b/frontend/views/product/view.php @@ -39,7 +39,7 @@ ], ]; } - $this->params[ 'breadcrumbs' ][] = $seo->title; + $this->params[ 'breadcrumbs' ][] = $seo->h1; $images = $model->images; if (empty($model->images)) { -- libgit2 0.21.4