Skip to content

Commit 5ef3a83

Browse files
committed
MC-32278: Position sort does not work in GraphQl.
- order by second
1 parent 7a742ff commit 5ef3a83

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
17171717
// optimize if using cat index
17181718
$filters = $this->_productLimitationFilters;
17191719
if (isset($filters['category_id']) || isset($filters['visibility'])) {
1720-
$this->getSelect()->order('cat_index.position ' . $dir);
1720+
$this->getSelect()->order(['cat_index.position ' . $dir, 'e.entity_id ' . $dir]);
17211721
} else {
17221722
$this->getSelect()->order('e.entity_id ' . $dir);
17231723
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ public function getResult(
121121
$searchCriteria->setCurrentPage(0);
122122
$itemsResults = $this->search->search($searchCriteria);
123123

124-
$searchCriteria->setPageSize($realPageSize)->setCurrentPage($realCurrentPage);
125-
126124
//Create copy of search criteria without conditions (conditions will be applied by joining search result)
127125
$searchCriteriaCopy = $this->searchCriteriaFactory->create()
128126
->setSortOrders($searchCriteria->getSortOrders())
@@ -144,7 +142,7 @@ public function getResult(
144142
}
145143
}
146144
}
147-
145+
//add root category or all root category children if category_id is not defined
148146
if ($categoryGroup) {
149147
$searchCriteriaCopy->setFilterGroups([$categoryGroup]);
150148
}

0 commit comments

Comments
 (0)