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

Reset previous sorting rules before adding an attribute sort rule #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

taskula
Copy link

@taskula taskula commented Sep 17, 2019

Our catalog widget in Magento 2.3.2 is sorting by created_at by default as seen:
"ORDER BY e.created_at desc, cat_index.position ASC LIMIT 10"

This PR resets previous sort rules and makes created_at sorting secondary.

Our catalog widget in Magento 2.3.2 is sorting by created_at by default as seen:
"ORDER BY `e`.`created_at` desc, `cat_index`.`position` ASC LIMIT 10"

This patch resets previous sort rules and makes created_at sorting secondary.
@rianorie
Copy link
Owner

@taskula Looks good! I'm curious though, why the load() call? That will negate the lazy loading..

@niclashoyer
Copy link

I just had the same issue and it really did not work when not using load(). Without the load() call the resulting SELECT query just did not have the ORDER BY clause.

@niclashoyer
Copy link

One other problem I noticed is that the collection is loaded correctly, sorted correctly, running the SQL query manually shows the correct order, but in the frontend the widget still shows another order 😞

@niclashoyer
Copy link

After some more digging I actually found the error on why it is not possible to sort by position:

When the product collection is created, Magento uses the default root category, because the widget can be embedded anywhere. Afterwars it is possible to add rules to filter for category id, but as the collection was created using the root category, the query uses the positions from the root category instead of the category that is filtered.

I worked around this by replacing the product collection with a new collection alltogether.

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

Successfully merging this pull request may close these issues.

3 participants