From 293e6d8b0c5594ea14afd17306ab42440b85c215 Mon Sep 17 00:00:00 2001 From: Oliver Skroblin Date: Wed, 7 Jun 2017 13:37:43 +0200 Subject: [PATCH] SW-18968 - Fix search sorting --- _sql/migrations/917-add-sorting-module.php | 45 +++++++++++++++---- .../sorting/classes/search_ranking_sorting.js | 4 +- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/_sql/migrations/917-add-sorting-module.php b/_sql/migrations/917-add-sorting-module.php index 9521fffe385..3508feb4562 100644 --- a/_sql/migrations/917-add-sorting-module.php +++ b/_sql/migrations/917-add-sorting-module.php @@ -1,4 +1,26 @@ addSql($sql); @@ -100,6 +122,7 @@ private function addDefaultSortings() /** * @param int $translationShopId * @param int $localeId + * * @return array */ private function getExistingSortingTranslations($translationShopId, $localeId) @@ -107,7 +130,7 @@ private function getExistingSortingTranslations($translationShopId, $localeId) $translations = $this->connection->query( "SELECT `name`, `value` FROM s_core_snippets WHERE `name` IN ('ListingSortRelevance', 'ListingSortRelease', 'ListingSortRating', 'ListingSortPriceHighest', 'ListingSortName', 'ListingSortPriceLowest') - AND shopID = " . $translationShopId . " AND localeID = " . $localeId + AND shopID = " . $translationShopId . ' AND localeID = ' . $localeId )->fetchAll(PDO::FETCH_ASSOC); $insert = []; @@ -133,17 +156,18 @@ private function getExistingSortingTranslations($translationShopId, $localeId) break; } } + return $insert; } private function importProductStreamSortings() { - $streamSortings = $this->connection->query("SELECT id, name, sorting FROM s_product_streams WHERE sorting IS NOT NULL")->fetchAll(PDO::FETCH_ASSOC); + $streamSortings = $this->connection->query('SELECT id, name, sorting FROM s_product_streams WHERE sorting IS NOT NULL')->fetchAll(PDO::FETCH_ASSOC); $newSortings = []; foreach ($streamSortings as $sorting) { $id = $this->getIdOfStreamSorting($sorting['sorting']); if ($id) { - $this->addSql("UPDATE s_product_streams SET sorting_id = " . (int) $id . " WHERE id = " . (int) $sorting['id']); + $this->addSql('UPDATE s_product_streams SET sorting_id = ' . (int) $id . ' WHERE id = ' . (int) $sorting['id']); continue; } $key = md5($sorting['sorting']); @@ -155,15 +179,16 @@ private function importProductStreamSortings() $this->addSql(" INSERT INTO `s_search_custom_sorting` (`label`, `active`, `display_in_categories`, `position`, `sortings`) VALUES -('".$name."', 1, 0, 0, '". str_replace("\\", "\\\\", $sorting['sorting']) ."'); +('" . $name . "', 1, 0, 0, '" . str_replace('\\', '\\\\', $sorting['sorting']) . "'); "); - $this->addSql("UPDATE s_product_streams SET sorting_id = (SELECT id FROM s_search_custom_sorting WHERE name = '". $name ."' LIMIT 1) WHERE id = " . (int) $sorting['id']); + $this->addSql("UPDATE s_product_streams SET sorting_id = (SELECT id FROM s_search_custom_sorting WHERE name = '" . $name . "' LIMIT 1) WHERE id = " . (int) $sorting['id']); } } /** * @param string $sorting + * * @return int|null */ private function getIdOfStreamSorting($sorting) @@ -183,6 +208,7 @@ private function getIdOfStreamSorting($sorting) if ($parameters['direction'] == 'desc') { return 4; } + return 3; case ReleaseDateSorting::class: return 1; @@ -191,12 +217,13 @@ private function getIdOfStreamSorting($sorting) case SearchRankingSorting::class: return 7; } + return null; } private function importSortingTranslations() { - $shops = $this->connection->query("SELECT id, main_id, locale_id FROM s_core_shops")->fetchAll(PDO::FETCH_ASSOC); + $shops = $this->connection->query('SELECT id, main_id, locale_id FROM s_core_shops')->fetchAll(PDO::FETCH_ASSOC); foreach ($shops as $shop) { $translationShopId = $shop['main_id'] ?: $shop['id']; @@ -207,7 +234,7 @@ private function importSortingTranslations() if (!empty($insert)) { $this->addSql( "INSERT IGNORE INTO s_core_translations (objecttype, objectdata, objectkey, objectlanguage) - VALUES ('custom_sorting', '" . serialize($insert) . "', '1', " . $shop['id'] . ")" + VALUES ('custom_sorting', '" . serialize($insert) . "', '1', " . $shop['id'] . ')' ); } } diff --git a/themes/Backend/ExtJs/backend/config/view/custom_search/sorting/classes/search_ranking_sorting.js b/themes/Backend/ExtJs/backend/config/view/custom_search/sorting/classes/search_ranking_sorting.js index 0d9ee0b3d85..a59db83cf80 100644 --- a/themes/Backend/ExtJs/backend/config/view/custom_search/sorting/classes/search_ranking_sorting.js +++ b/themes/Backend/ExtJs/backend/config/view/custom_search/sorting/classes/search_ranking_sorting.js @@ -57,7 +57,9 @@ Ext.define('Shopware.apps.Config.view.custom_search.sorting.classes.SearchRankin return { 'class': 'Shopware\\Bundle\\SearchBundle\\Sorting\\SearchRankingSorting', 'label': '{s name="search_ranking_sorting"}{/s}', - 'parameters': { } + 'parameters': { + 'direction': 'DESC' + } }; } });