magento2: Position sort does not work in GraphQl.
Preconditions (*)
- Magento 2.3.4 Open Source
Steps to reproduce (*)
- Install demo data
- Assign positions to all products in the Watches category (id: 6)
- Run the following GraphQl Query.
query category {
categoryList(
filters: {ids: {eq: "6"}}
) {
products(
sort: {
position: ASC
}
) {
items {
id
}
total_count
}
}
}
Expected result (*)
{
"data": {
"categoryList": [
{
"products": {
"items": [
{
"id": 43
},
{
"id": 41
},
{
"id": 39
},
{
"id": 37
},
{
"id": 36
},
{
"id": 38
},
{
"id": 40
},
{
"id": 42
},
{
"id": 44
}
],
"total_count": 9
}
}
]
}
}
Actual result (*)
{
"data": {
"categoryList": [
{
"products": {
"items": [
{
"id": 36
},
{
"id": 37
},
{
"id": 38
},
{
"id": 39
},
{
"id": 40
},
{
"id": 41
},
{
"id": 42
},
{
"id": 43
},
{
"id": 44
}
],
"total_count": 9
}
}
]
}
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (5 by maintainers)
I’m using magento 2.3.5-p1, and this is how i fixed it based on @radub and @Hexmage answers and using magento plugins:
in Vendor/etc/di.xml:
in Vendor/CategoryProductsSortFix/Model/Resolver/Products/DataProvider/CatalogCategoryProductJoinProcessor.php:
in Vendor\CategoryProductsSortFix\Plugin\BeforeProductSearch.php:
Doing the following resolves the issue, but it isn’t a nice/good solution. This adds the category filterGroup to the searchCriteria, because position sort requires a join on the category index.
\Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ProductSearch::getList