Developer forum

Forum » Development » Sorting with filtering

Sorting with filtering

Martijn Bokhove
Reply

Hi

Is it possible to change to sortingof products when using filtering?
I know we can change it with an notificationsubsciber, to sort it on price, alphabetical, etc. But we want it to use the option 'user defined'.

In the Ecom Module in the CMS we checked the option 'user definded' (otherwise we were not able to sort it with the notificationsubscriber).

When entering a productlist without filtering, the products are sorted as defined in the CMS.
When entering a productlist with filtering, for example the GroupID, the productlist is exactly the same but the sorting is wrong. I can't see where the sorting is based on as soon as we use te filtering.

We already tried to use  'args.Products.Sort(eCommerce.Products.ProductCollection.SortBy.UserDefined)' in the notificationsubscriber, without any luck.

Are there other options to overrule the productlist in the notificationsubscriber and let it sort user defined when using filtering?

Gr
Martijn


Replies

 
Steen Nørgaard Perdersen
Reply
Make sure you empty the list of products, and fill it again in the wanted order..

Using a eCommerce.ProductList.BeforePaging:
var list = (eCommerce.ProductList.BeforePagingArgs) args;

List<Product> lt = list.Products.Cast<Product>().ToList(); // copy contents
// Do your sorting
// and then put the products back in....

list.Products.Clear();

foreach (Product product in lt){list.Products.Add(product);}
 




 
Martijn Bokhove
Reply
Hi

I tried your solution, and it gets a little strange.
The code is now in the notificationsubribers for BeforePaging and BeforeSort.

When I sort it on a page with filtering parameters in the URL, the sorting (codebehind) is correct when it's sorted User Defined.
Looking at the latest breakpoint in the code (BeforePaging -> args.products), it's sorted correct. But when the page shows, it's not correct anymore. So it looks like it's gets overruled somewhere between sorting/paging and rendering.

The most strange thing is, when I sort it alphabetical, it shows correct at the latest breakpoint andalso on te page. When it's sorted the same way, but now User Defined, it's shows correct at the latest breakpoint, but not on the page.

Wat can I do?

Gr.
Martijn

 
Pavel Volgarev
Reply
Hi Martijn and Steen,

I've had a quick look at the source code and it seems like the resulting product collection remains unchanged after the "BeforePaging" notification is fired.

Anyway, you don't need to write any custom code in order to be able to sort products by "User defined" option (even when applying search filters). The behavior that you described has been confirmed as a bug (#6732) and will be fixed soon.

Thanks.

-- Pavel 

 

You must be logged in to post in the forum