elasticsuite icon indicating copy to clipboard operation
elasticsuite copied to clipboard

How to set different sort direction per category?

Open ioweb-gr opened this issue 5 months ago • 13 comments

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

ioweb-gr avatar Feb 15 '24 17:02 ioweb-gr

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

vahonc avatar Feb 16 '24 11:02 vahonc

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

romainruaud avatar Feb 19 '24 14:02 romainruaud

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 avatar Feb 19 '24 17:02 ioweb-gr

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 avatar Feb 22 '24 12:02 ioweb-gr

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?

ioweb-gr avatar Feb 22 '24 12:02 ioweb-gr

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

romainruaud avatar Feb 26 '24 14:02 romainruaud

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

ioweb-gr avatar Feb 26 '24 14:02 ioweb-gr

@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

romainruaud avatar Feb 26 '24 14:02 romainruaud

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

ioweb-gr avatar Feb 26 '24 14:02 ioweb-gr

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

romainruaud avatar Feb 26 '24 15:02 romainruaud

@romainruaud Great :)

ioweb-gr avatar Feb 27 '24 05:02 ioweb-gr