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

How to set different sort direction per category? #3184

Closed
ioweb-gr opened this issue Feb 15, 2024 · 17 comments
Closed

How to set different sort direction per category? #3184

ioweb-gr opened this issue Feb 15, 2024 · 17 comments
Assignees
Labels

Comments

@ioweb-gr
Copy link

Is your question related to a problem? Please describe.
Since installing smile elastic suite we lost the ability to sort in both directions by position. On our store, we have by default set up so that products are ordered by date created_at descending so that the newest products are on top. However for some categories like sales categories, we would like to manually sort some products by position not all of them.

After installing the module though, the position field is no longer appearing. Instead we have to disable automatic sort from the products one by one and then they will be inserted in the bottom instead of the top. However we cannot change the sort direction for the category to invert the ordering. We have to manually reorder all products and move them in the inverse direction.

And we can't for example push the product after the automatic sorted ones to change the direction
image

So we have no way to control the direction itself between mixed manual and automatic products.

Now imagine a category with 2000 products where the user has to manually click every one of them to make them manual and then rearrange them manually one by one in the inverse way.

This is really problematic, is there a workaround or a recommended way to fix this on category level?

Additional context

@vahonc
Copy link
Collaborator

vahonc commented Feb 16, 2024

Hello @ioweb-gr,

There is already a similar issue #3179, so you can take some inspiration from there.

As Roma already said:

There is no column to change the position of product in admin, you should drag and drop them in the listing, by switching them from "Automatic sort" to "Manual Sort".

The "Use Default position" for a specific store view is just a mechanism to determine if you want to use the same positions at the "Default" level and at the "Store" level. It's not a way to get back the old fashioned grid.

We do not recommend setting a huge amount of products to a pinned position, that's barely unusable for the endusers, it's better to use boosts (optimizers) to create ranking rules.

Check our Wiki about how you could customize the product sorting.

BR,
Vadym

@romainruaud
Copy link
Collaborator

Hi @ioweb-gr

I don't understand your Use Case.

If you want to get back your existing positions, you can insert them in the "smile_virtualcategory_catalog_category_product_position" table.

You're willing to sort by position "DESC" instead of "ASC" ?

You could probably consider adding a plugin here : https://github.com/Smile-SA/elasticsuite/blob/2.11.x/src/module-elasticsuite-core/Search/Request/SortOrderInterface.php#L65

@ioweb-gr
Copy link
Author

Hi my use case is fairly simple.

My whole website needs to sort products by created_at descending and we did that. It works perfectly.

However for a few categories we need to change sort on demand by the admin to use sort by position and ascending direction.

With smile elastic suite enabled this is impossible now because we can switch the attribute to position for this category by default but the direction will stay descending. The admin cannot change it

Without smile this would not be a problem because he could position the products inverse and due to descending order he could show what he wants.

However with smile enabled, the products using manual sort will be pushed to the top only (when sort direction is ascending). But in our case direction is descending so they appear in the last page instead of the top of the first page

@ioweb-gr
Copy link
Author

ioweb-gr commented Feb 22, 2024

Let's say I have products 1-5

I want to sort like this in one category

Product ID Created At Position
Product 1 2024-02-17 1
Product 4 2024-02-20 2
Product 2 2024-02-18 3
Product 3 2024-02-19 4
Product 5 2024-02-21 5

This is the default sorting order based on the created_at date, from the newest (Product 5) to the oldest (Product 1).

Product ID Created At Position
Product 5 2024-02-21 1
Product 4 2024-02-20 2
Product 3 2024-02-19 3
Product 2 2024-02-18 4
Product 1 2024-02-17 5

When using smile elastic suite if I manually set position for Products 1,4 they will appear in the backend on the top. However on the frontend because the sort order is descending, the end result will be

Product ID Created At Position
Product 5 2024-02-21 1
Product 3 2024-02-19 2
Product 2 2024-02-18 3
Product 4 2024-02-20 4
Product 1 2024-02-17 5

On the old magento, I could set the position number in inverse to accommodate the descending order, in smile it's not possible so we lose functionality

I hope these examples make it clear now

@ioweb-gr
Copy link
Author

In terms of possible solutions, would it be possible to add a custom attribute in categories for the sort direction (by default) and have smile elastic suite solution honor this?

@romainruaud
Copy link
Collaborator

Hello @ioweb-gr

According to your use case, I think it's more suitable to allow "Created At" to be sortable. This way, you'd be able to chose this attribute as the default sort order for categories.

So @vahonc can you try to :

  • create a setup that change the created_at and updated_at to is_user_defined = 1 so that people can edit them in the back-office ?
  • then try to change the created_at attribute to sortable through the back-office.

And check if this can then be used for sorting categories or if it requires additional work by our side.

regards

@vahonc vahonc self-assigned this Feb 26, 2024
@ioweb-gr
Copy link
Author

ioweb-gr commented Feb 26, 2024

I think you missed the point the problem is not to add created at descending as the sorting. We did that.

The problem is changing one category to position ascending

We can't set the default direction per category

@romainruaud
Copy link
Collaborator

@ioweb-gr the default sorting is "position ascending". You mean you want to change it to "position descending" for a particular category, don't you ?

We could allow to edit the sort direction per category, this could be interesting.

Regards

@ioweb-gr
Copy link
Author

Yes exactly adding this option solves the issue. But I want to make clear this was possible in default M2. The ability was lost due to the drag and drop ui of elastic.

I have already a way we can simplify this example.

Can you now using smile elastic suite push 1 product to the bottom of the list if you sort by position? In order to do that you have to set all products to manual sort order and drag and drop to end when sorted by position ascending.

In default M2 it's easy because you set the product position as a high number and it will move to bottom

@romainruaud
Copy link
Collaborator

Ok @ioweb-gr now I understand more.

Can you now using smile elastic suite push 1 product to the bottom of the list if you sort by position? In order to do that you have to set all products to manual sort order and drag and drop to end when sorted by position ascending.

In default M2 it's easy because you set the product position as a high number and it will move to bottom

So the answer is "No" until you are able to set the sort direction per category.

@vahonc in parallel of the previous comment about the dates, can you work on a PR to add the ability to change the sort direction per category ?

The idea is :

  • Add an attribute named sort_direction to each category. This attribute will have a source model allowing only DESC and ASC. Such a source model probably exists in Magento elsewhere.
  • Ensure this attribute is displayed just after the available_sort_by attribute in the category edit form.
  • Then ensure in Front-Office that the value of this attribute is used by default when accessing a category.

Regards

@ioweb-gr
Copy link
Author

@romainruaud Great :)

vahonc added a commit to vahonc/elasticsuite that referenced this issue Mar 18, 2024
vahonc added a commit to vahonc/elasticsuite that referenced this issue Mar 18, 2024
vahonc added a commit to vahonc/elasticsuite that referenced this issue Mar 18, 2024
romainruaud pushed a commit to romainruaud/elasticsuite that referenced this issue Apr 18, 2024
romainruaud pushed a commit to romainruaud/elasticsuite that referenced this issue Apr 18, 2024
romainruaud pushed a commit to romainruaud/elasticsuite that referenced this issue Apr 18, 2024
@mdesplenter
Copy link

This new functionality was breaking my Magento 2.4.5-p7 shop. I set the version to 2.10.19.3 for now.

It's a related commit 7d54338
which is removing the new sort_order attribute, which is why I (think) get this error:

TypeError: Return value of Smile\ElasticsuiteVirtualCategory\Model\Preview::getSortBy() must be of the type string, null returned in /vendor/smile/elasticsuite/src/module-elasticsuite-virtual-category/Model/Preview.php:224

Updated from 2.10.19.1 to 2.10.20.1

@romainruaud
Copy link
Collaborator

@mdesplenter can you please create a separated issue for this ?

Regards

@jesse-thomas
Copy link

This is an awesome feature, unfortionatly it defaults to ASC and we need DESC as the default. I wrote a quick patch because I'm busy. But having a default sort direction in the config below 'Product Listing Sort by" and adding a use default check box on the category would be perfect.

@romainruaud
Copy link
Collaborator

@jesse-thomas could you write a new issue with your needs ? I agree it would be great, we'll gladly implement it.

But I'd like to close this old issue because the purpose of this ticket has been implemented.

Regards

@jesse-thomas
Copy link

jesse-thomas commented Jul 23, 2024

@romainruaud will do, thanks!

I added a feature request #3333

@romainruaud
Copy link
Collaborator

I close this ticket since it's been implement. Let's follow the new feature request on #3333

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

Successfully merging a pull request may close this issue.

5 participants