Skip to content
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

#26708 Fix ORDER BY has two similar conditions by removing duplicated entries #26754

Closed
wants to merge 1 commit into from
Closed

Conversation

jonatanrdsantos
Copy link
Member

@jonatanrdsantos jonatanrdsantos commented Feb 7, 2020

Description (*)

Fixed the order by duplication problem.

Fixed Issues (if relevant)

  1. ORDER BY has two similar conditions #26708: ORDER BY has two similar conditions

Manual testing scenarios (*)

  1. We have products in category
  2. Go to app/code/Magento/Catalog/Block/Product/ListProduct.php and add:
  3. Go to page on category

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 7, 2020

Hi @joridos. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

Copy link
Contributor

@lenaorobei lenaorobei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to dig deeper here and understand the reason of duplicate values, but not just filtering them. I would suggest to debug and find the place where previous orderBy is being added.

@jonatanrdsantos
Copy link
Member Author

jonatanrdsantos commented Feb 7, 2020

I think we need to dig deeper here and understand the reason of duplicate values, but not just filtering them. I would suggest to debug and find the place where previous orderBy is being added.

He is called twice because _beforeToHtml calls _getProductCollection that calls initializeProductCollection that finally calls addToolbarBlock but in sequence on _beforeToHtml we call addToolbarBlock again. those changes are introduce in #11473

Back on sort order creation on Magento\Catalog\Model\ResourceModel\Product\Collection whe have addAttributeToSort that uses $this->getSelect()->order('cat_index.position ' . $dir); to set order position, and not some abstract method like $this->setOrder();.

Digging deep I could see that Magento\Framework\Data\Collection\AbstractDb has a _setOrder that do this kind of validation:

unset($this->_orders[$field]);
        // avoid ordering by the same field twice
        if ($unshift) {
            $orders = [$field => $direction];
            foreach ($this->_orders as $key => $dir) {
                $orders[$key] = $dir;
            }
            $this->_orders = $orders;
        } else {
            $this->_orders[$field] = $direction;
        }

And because of on addAttributeToSort set order direct to the select query every time that addToolbarBlock is called the position get duplicated.

@lenaorobei do u have any suggeston?

@lenaorobei
Copy link
Contributor

Wow, that's interesting. Let's try to remove redundant addToolbarBlock and see what's happening.

@jonatanrdsantos
Copy link
Member Author

Wow, that's interesting. Let's try to remove redundant addToolbarBlock and see what's happening.

I remove the addToolbarBlock from initializeProductCollection seens to fix the problem.

@lenaorobei
Copy link
Contributor

@lenaorobei
Copy link
Contributor

@joridos are you still up to finishing this PR?

@jonatanrdsantos
Copy link
Member Author

@lenaorobei Right now i'm with no free time work with this, sorry :(

@lenaorobei
Copy link
Contributor

@joridos I will have to close this PR so somebody else can take this issue. Feel free to reopen at any time if you want to continue working on it.

@lenaorobei lenaorobei closed this Mar 9, 2020
@m2-assistant
Copy link

m2-assistant bot commented Mar 9, 2020

Hi @joridos, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants