-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Added a filter to sort categories by position by default #29301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a filter to sort categories by position by default #29301
Conversation
Hi @Dnyomo. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run WebAPI Tests |
@magento run WebAPI Tests |
@@ -71,6 +72,7 @@ public function getResult(array $criteria, StoreInterface $store) | |||
$categoryIds = []; | |||
$criteria[Filter::ARGUMENT_NAME] = $this->formatMatchFilters($criteria['filters'], $store); | |||
$criteria[Filter::ARGUMENT_NAME][CategoryInterface::KEY_IS_ACTIVE] = ['eq' => 1]; | |||
$criteria[Sort::ARGUMENT_NAME][CategoryInterface::KEY_POSITION] = ['ASC']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dnyomo can you please verify and confirm that for categories (e.g in menu) also have a sort order by position ASC ?
…CriteriaBuilder.php Remove the _id from the order that is being passed to the product collection in ProductSearch.php Updated the position to be DESC passed to the product collection in ProductSearch.php Updated the ProductSearchTest.php to have the items in the attended order
…CriteriaBuilder.php Remove the _id from the order that is being passed to the product collection in ProductSearch.php Updated the position to be DESC passed to the product collection in ProductSearch.php Updated the ProductSearchTest.php to have the items in the attended order
@magento run WebAPI Tests, Integration Tests |
{ | ||
$ordersArray = []; | ||
$sortOrders = $searchCriteria->getSortOrders(); | ||
if (is_array($sortOrders)) { | ||
foreach ($sortOrders as $sortOrder) { | ||
$ordersArray[$sortOrder->getField()] = $sortOrder->getDirection(); | ||
if ($sortOrder->getField() !== '_id') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this check? It will ignore any sort order defined by user in GQL query
@@ -104,6 +104,7 @@ public function build(array $args, bool $includeAggregation): SearchCriteriaInte | |||
$this->addDefaultSortOrder($searchCriteria, $isSearch); | |||
} | |||
|
|||
$this->addEntityIdSort($searchCriteria, $isSearch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please verify the behavior for GQL query which will filter by category id/ids, e.g.
{
products(filter: {category_id: {in: ["3", "5"]}}) {
items {
sku
}
}
}
{
products(filter: {category_id: {eq:"3"}}) {
items {
sku
}
}
}
In these examples we should add order by "position ASC" only for the second case.
And only if the sort was provided explicitly in GQL query it should be added as is.
I'm afraid that current implementation in addDefaultSortOrder method don't take this into account
I think we dont' have specific tests for that and it make sense to add this for GQL coverage
(@yaroslavGoncharuk can you help us with steps?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did test this and because this method (\Magento\Catalog\Model\ResourceModel\Product\Collection::addAttributeToSort line 1749) converts the attribute position to entity_id. I think it makes sense to always have a position set as a sort.
@magento run WebAPI Tests |
@magento run WebAPI Tests |
@magento run WebAPI Tests |
@Dnyomo Query with condition eq returns "Internal server error"
Works well if eq is replaced by in OR sort: {price: ASC} argument is added |
…array. Reverted the tests back to check on products
@magento run WebAPI Tests |
…array. Reverted the tests back to check on products
@magento run WebAPI Tests |
@magento run all tests |
@Dnyomo can you please check static tests? |
@magento run Functional Tests CE,Functional Tests B2B |
@magento run Functional Tests B2B |
…m:Dnyomo/magento2 into storefront-issue_104_default_sort_order_b
@magento run Static Tests |
@magento run Static Tests |
@magento run Static Tests |
@magento run Static Tests |
@magento run Static Tests |
@magento run all tests |
@magento run Functional Tests B2B |
Description (*)
This fixed a bug where the default GraphQL Category method does not sort by category position. By adding this filter results are returned in the correct order.
Related Pull Requests
magento/catalog-storefront#173
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)