Skip to content

Commit 47bf48e

Browse files
committed
Merge pull request #5049 in SW/shopware from sw-18968/5.3/fix-search-sorting to 5.3
* commit '293e6d8b0c5594ea14afd17306ab42440b85c215': SW-18968 - Fix search sorting
2 parents 13eb037 + 293e6d8 commit 47bf48e

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

_sql/migrations/917-add-sorting-module.php

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
<?php
2+
/**
3+
* Shopware 5
4+
* Copyright (c) shopware AG
5+
*
6+
* According to our dual licensing model, this program can be used either
7+
* under the terms of the GNU Affero General Public License, version 3,
8+
* or under a proprietary license.
9+
*
10+
* The texts of the GNU Affero General Public License with an additional
11+
* permission and of our proprietary license can be found at and
12+
* in the LICENSE file you have received along with this program.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* "Shopware" is a registered trademark of shopware AG.
20+
* The licensing of the program under the AGPLv3 does not imply a
21+
* trademark license. Therefore any rights, title and interest in
22+
* our trademarks remain entirely with us.
23+
*/
224

325
use Shopware\Bundle\SearchBundle\Sorting\PopularitySorting;
426
use Shopware\Bundle\SearchBundle\Sorting\PriceSorting;
@@ -10,7 +32,7 @@
1032
class Migrations_Migration917 extends AbstractMigration
1133
{
1234
/**
13-
* @inheritdoc
35+
* {@inheritdoc}
1436
*/
1537
public function up($modus)
1638
{
@@ -91,7 +113,7 @@ private function addDefaultSortings()
91113
(3, 'Niedrigster Preis', 1, 1, 2, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\PriceSorting":{"direction":"ASC"}}'),
92114
(4, 'Höchster Preis', 1, 1, 3, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\PriceSorting":{"direction":"DESC"}}'),
93115
(5, 'Artikelbezeichnung', 1, 1, 4, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\ProductNameSorting":{"direction":"ASC"}}'),
94-
(7, 'Beste Ergebnisse', 1, 0, 6, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\SearchRankingSorting":{}}');
116+
(7, 'Beste Ergebnisse', 1, 0, 6, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\SearchRankingSorting":{"direction":"DESC"}}');
95117
SQL;
96118

97119
$this->addSql($sql);
@@ -100,14 +122,15 @@ private function addDefaultSortings()
100122
/**
101123
* @param int $translationShopId
102124
* @param int $localeId
125+
*
103126
* @return array
104127
*/
105128
private function getExistingSortingTranslations($translationShopId, $localeId)
106129
{
107130
$translations = $this->connection->query(
108131
"SELECT `name`, `value` FROM s_core_snippets WHERE `name`
109132
IN ('ListingSortRelevance', 'ListingSortRelease', 'ListingSortRating', 'ListingSortPriceHighest', 'ListingSortName', 'ListingSortPriceLowest')
110-
AND shopID = " . $translationShopId . " AND localeID = " . $localeId
133+
AND shopID = " . $translationShopId . ' AND localeID = ' . $localeId
111134
)->fetchAll(PDO::FETCH_ASSOC);
112135

113136
$insert = [];
@@ -133,17 +156,18 @@ private function getExistingSortingTranslations($translationShopId, $localeId)
133156
break;
134157
}
135158
}
159+
136160
return $insert;
137161
}
138162

139163
private function importProductStreamSortings()
140164
{
141-
$streamSortings = $this->connection->query("SELECT id, name, sorting FROM s_product_streams WHERE sorting IS NOT NULL")->fetchAll(PDO::FETCH_ASSOC);
165+
$streamSortings = $this->connection->query('SELECT id, name, sorting FROM s_product_streams WHERE sorting IS NOT NULL')->fetchAll(PDO::FETCH_ASSOC);
142166
$newSortings = [];
143167
foreach ($streamSortings as $sorting) {
144168
$id = $this->getIdOfStreamSorting($sorting['sorting']);
145169
if ($id) {
146-
$this->addSql("UPDATE s_product_streams SET sorting_id = " . (int) $id . " WHERE id = " . (int) $sorting['id']);
170+
$this->addSql('UPDATE s_product_streams SET sorting_id = ' . (int) $id . ' WHERE id = ' . (int) $sorting['id']);
147171
continue;
148172
}
149173
$key = md5($sorting['sorting']);
@@ -155,15 +179,16 @@ private function importProductStreamSortings()
155179

156180
$this->addSql("
157181
INSERT INTO `s_search_custom_sorting` (`label`, `active`, `display_in_categories`, `position`, `sortings`) VALUES
158-
('".$name."', 1, 0, 0, '". str_replace("\\", "\\\\", $sorting['sorting']) ."');
182+
('" . $name . "', 1, 0, 0, '" . str_replace('\\', '\\\\', $sorting['sorting']) . "');
159183
");
160184

161-
$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']);
185+
$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']);
162186
}
163187
}
164188

165189
/**
166190
* @param string $sorting
191+
*
167192
* @return int|null
168193
*/
169194
private function getIdOfStreamSorting($sorting)
@@ -183,6 +208,7 @@ private function getIdOfStreamSorting($sorting)
183208
if ($parameters['direction'] == 'desc') {
184209
return 4;
185210
}
211+
186212
return 3;
187213
case ReleaseDateSorting::class:
188214
return 1;
@@ -191,12 +217,13 @@ private function getIdOfStreamSorting($sorting)
191217
case SearchRankingSorting::class:
192218
return 7;
193219
}
220+
194221
return null;
195222
}
196223

197224
private function importSortingTranslations()
198225
{
199-
$shops = $this->connection->query("SELECT id, main_id, locale_id FROM s_core_shops")->fetchAll(PDO::FETCH_ASSOC);
226+
$shops = $this->connection->query('SELECT id, main_id, locale_id FROM s_core_shops')->fetchAll(PDO::FETCH_ASSOC);
200227

201228
foreach ($shops as $shop) {
202229
$translationShopId = $shop['main_id'] ?: $shop['id'];
@@ -207,7 +234,7 @@ private function importSortingTranslations()
207234
if (!empty($insert)) {
208235
$this->addSql(
209236
"INSERT IGNORE INTO s_core_translations (objecttype, objectdata, objectkey, objectlanguage)
210-
VALUES ('custom_sorting', '" . serialize($insert) . "', '1', " . $shop['id'] . ")"
237+
VALUES ('custom_sorting', '" . serialize($insert) . "', '1', " . $shop['id'] . ')'
211238
);
212239
}
213240
}

themes/Backend/ExtJs/backend/config/view/custom_search/sorting/classes/search_ranking_sorting.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ Ext.define('Shopware.apps.Config.view.custom_search.sorting.classes.SearchRankin
5757
return {
5858
'class': 'Shopware\\Bundle\\SearchBundle\\Sorting\\SearchRankingSorting',
5959
'label': '{s name="search_ranking_sorting"}{/s}',
60-
'parameters': { }
60+
'parameters': {
61+
'direction': 'DESC'
62+
}
6163
};
6264
}
6365
});

0 commit comments

Comments
 (0)