From 33a3676c241815a6b7203da6b36e05f1933e45af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=A4umer?= Date: Thu, 2 Jul 2015 14:52:06 +0200 Subject: [PATCH] SW-10310 - added support for the s_core_translations to the SEO URL generation --- UPGRADE.md | 1 + engine/Shopware/Core/sRewriteTable.php | 49 ++++++++++++++++--- .../Core/RebuildIndex/Controllers/Seo.php | 2 + 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 0f1be2b4e6c..fe3efb16b27 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -74,6 +74,7 @@ In this document you will find a changelog of the important changes related to t * Use `bin/console sw:snippets:validate ` to check the validity of your snippets. * Defining a snippet value in multiple lines is deprecated. * All snippet values that don't pass the validation should be refactored. +* The method `getSeoArticleQuery` in `sRewriteTable.php` was changed to select the translations for the article attributes. ## 5.0.1 * Create `sw:theme:dump:configuration` command to generate watch files for theme compiling diff --git a/engine/Shopware/Core/sRewriteTable.php b/engine/Shopware/Core/sRewriteTable.php index cc56334b8ea..737ed0d0eed 100644 --- a/engine/Shopware/Core/sRewriteTable.php +++ b/engine/Shopware/Core/sRewriteTable.php @@ -906,6 +906,8 @@ public function sCreateRewriteTableArticles($lastUpdate, $limit = 1000) ) ); + $result = $this->mapArticleTranslationObjectData($result); + $result = Shopware()->Events()->filter( 'Shopware_Modules_RewriteTable_sCreateRewriteTableArticles_filterArticles', $result, @@ -947,9 +949,8 @@ public function sCreateRewriteTableArticles($lastUpdate, $limit = 1000) public function getSeoArticleQuery() { return " - SELECT a.*, IF(atr.name IS NULL OR atr.name='', a.name, atr.name) as name, - d.ordernumber, d.suppliernumber, s.name as supplier, datum as date, - d.releasedate, changetime as changed, metaTitle, at.attr1, at.attr2, + SELECT a.*, d.ordernumber, d.suppliernumber, s.name as supplier, datum as date, + d.releasedate, changetime as changed, metaTitle, ct.objectdata, at.attr1, at.attr2, at.attr3, at.attr4, at.attr5, at.attr6, at.attr7, at.attr8, at.attr9, at.attr10,at.attr11, at.attr12, at.attr13, at.attr14, at.attr15, at.attr16, at.attr17, at.attr18, at.attr19, at.attr20 @@ -968,9 +969,10 @@ public function getSeoArticleQuery() LEFT JOIN s_articles_attributes at ON at.articledetailsID=d.id - LEFT JOIN s_articles_translations atr - ON atr.articleID=a.id - AND atr.languageID=? + LEFT JOIN s_core_translations ct + ON ct.objectkey=a.id + AND ct.objectlanguage=? + AND ct.objecttype='article' LEFT JOIN s_articles_supplier s ON s.id=a.supplierID @@ -1274,4 +1276,39 @@ private function insertStaticPageUrls($offset, $limit) $this->sInsertUrl($org_path, $path); } } + + /** + * Maps the translation of the objectdata from the s_core_translations in the article array + * @param array $articles + * @return mixed + */ + public function mapArticleTranslationObjectData($articles) + { + foreach ($articles as &$article) { + if (empty($article['objectdata'])) { + unset($article['objectdata']); + continue; + } + + $data = unserialize($article['objectdata']); + if (!$data) { + continue; + } + + $data['name'] = (!empty($data['txtArtikel'])) ? $data['txtArtikel'] : $article['name']; + $data['description_long'] = (!empty($data['txtlangbeschreibung'])) ? $data['txtlangbeschreibung'] : $article['description_long']; + $data['description'] = (!empty($data['txtshortdescription'])) ? $data['txtshortdescription'] : $article['description']; + $data['keywords'] = (!empty($data['txtkeywords'])) ? $data['txtkeywords'] : $article['keykwords']; + + unset($article['objectdata']); + unset($data['txtArtikel']); + unset($data['txtlangbeschreibung']); + unset($data['txtlangbeschreibung']); + unset($data['txtkeywords']); + + $article = array_merge($article, $data); + } + + return $articles; + } } diff --git a/engine/Shopware/Plugins/Default/Core/RebuildIndex/Controllers/Seo.php b/engine/Shopware/Plugins/Default/Core/RebuildIndex/Controllers/Seo.php index e1c8ec9ce54..d8be3ac5a0e 100644 --- a/engine/Shopware/Plugins/Default/Core/RebuildIndex/Controllers/Seo.php +++ b/engine/Shopware/Plugins/Default/Core/RebuildIndex/Controllers/Seo.php @@ -213,6 +213,8 @@ protected function seoArticle($offset, $limit, $shop) '1900-01-01' )); + $articles = $this->RewriteTable()->mapArticleTranslationObjectData($articles); + $articles = $this->get('events')->filter( 'Shopware_Controllers_Backend_Seo_seoArticle_filterArticles', $articles,