Skip to content

Commit

Permalink
Merge pull request #5049 in SW/shopware from sw-18968/5.3/fix-search-…
Browse files Browse the repository at this point in the history
…sorting to 5.3

* commit '293e6d8b0c5594ea14afd17306ab42440b85c215':
  SW-18968 - Fix search sorting
  • Loading branch information
janbuecker committed Jun 7, 2017
2 parents 13eb037 + 293e6d8 commit 47bf48e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
45 changes: 36 additions & 9 deletions _sql/migrations/917-add-sorting-module.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
<?php
/**
* Shopware 5
* Copyright (c) shopware AG
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* "Shopware" is a registered trademark of shopware AG.
* The licensing of the program under the AGPLv3 does not imply a
* trademark license. Therefore any rights, title and interest in
* our trademarks remain entirely with us.
*/

use Shopware\Bundle\SearchBundle\Sorting\PopularitySorting;
use Shopware\Bundle\SearchBundle\Sorting\PriceSorting;
Expand All @@ -10,7 +32,7 @@
class Migrations_Migration917 extends AbstractMigration
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function up($modus)
{
Expand Down Expand Up @@ -91,7 +113,7 @@ private function addDefaultSortings()
(3, 'Niedrigster Preis', 1, 1, 2, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\PriceSorting":{"direction":"ASC"}}'),
(4, 'Höchster Preis', 1, 1, 3, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\PriceSorting":{"direction":"DESC"}}'),
(5, 'Artikelbezeichnung', 1, 1, 4, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\ProductNameSorting":{"direction":"ASC"}}'),
(7, 'Beste Ergebnisse', 1, 0, 6, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\SearchRankingSorting":{}}');
(7, 'Beste Ergebnisse', 1, 0, 6, '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Sorting\\\\\\\SearchRankingSorting":{"direction":"DESC"}}');
SQL;

$this->addSql($sql);
Expand All @@ -100,14 +122,15 @@ private function addDefaultSortings()
/**
* @param int $translationShopId
* @param int $localeId
*
* @return array
*/
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 = [];
Expand All @@ -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']);
Expand All @@ -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)
Expand All @@ -183,6 +208,7 @@ private function getIdOfStreamSorting($sorting)
if ($parameters['direction'] == 'desc') {
return 4;
}

return 3;
case ReleaseDateSorting::class:
return 1;
Expand All @@ -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'];
Expand All @@ -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'] . ')'
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
};
}
});
Expand Down

0 comments on commit 47bf48e

Please sign in to comment.