-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fix sort order in \Magento\Framework\Api\Search\SearchCriteriaBuilder #37732
base: 2.4-develop
Are you sure you want to change the base?
Fix sort order in \Magento\Framework\Api\Search\SearchCriteriaBuilder #37732
Conversation
Hi @smartexcan. Thank you for your contribution! Add the comment under your pull request to deploy test or vanilla Magento instance:
❗ Automated tests can be triggered manually with an appropriate comment:
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
$sortOrder = $this->sortOrderBuilder->setDirection($direction) | ||
->setField($field) | ||
->create(); | ||
$this->sortOrders = [$sortOrder]; |
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.
When you multiple times will call the addSortOrder method, it will replace sort orders. I think it's not the expected result.
In stead, I think we should add a new sort order to the sortOrders array.
What do you think?
Also, I think we should cover it with unit or integration test. Could you please do so?
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 only had it replacing sort orders as that is what it was doing previously. If adding multiple sort orders is desired we can update it to do so.
As for tests, i will look into how to make those, havent done any before
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've changed the addSortOrder
method to add multiple sort orders, and added a setSortOrders
method to replace the sort orders in the builder, which is the same functionality as the regular SearchCriteriaBuilder.
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
I haven't written a unit test before, so not sure if this is correct, but here is a start of something.
|
Also the semantic version checker test failed due to addition of |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues. |
B2B integration test is failing due to this change. Before changes in the pr, Now the
An additional check should be added to that data provider to check if |
The original issue this PR was created to fix looks to be mitigated as of version 2.4.6 thanks to 967f817. I'm going to leave this PR open though, since the original use of the SortOrderBuilder in the changed file is very strange and I don't like to recommend that it's used that way. |
Description (*)
When using
Magento\Framework\Api\SortOrderBuilder
while loading a ui listing component (outside of the base DataProvider), trying to sort some columns might not work, depending on which column is being sorted.If the column applies its sort order after the SortOrderBuilder is used, the sort will work.
The issue is in the
\Magento\Framework\Api\Search\SearchCriteriaBuilder
class.Column ui components apply their sort order to the DataProvider, which adds it to the SearchCriteriaBuilder.
magento2/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php
Lines 84 to 89 in 41883fa
Because the SortOrder object is not created until the SearchCriteriaBuilder create() method is called, other code can use SortOrderBuilder and create an object from it, resulting in the fields from the Column no longer being present.
magento2/lib/internal/Magento/Framework/Api/Search/SearchCriteriaBuilder.php
Line 63 in 41883fa
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)