Developer forum

Forum » Development » Custom sorting of productlist

Custom sorting of productlist

Emil Ryberg
Reply

I am trying to create a custom sorting of productlist using Index that have pagination.

When i try to use BeforeSortObserver, BeforePagingObserver or BeforeRenderObserver i only get the 15 products that is shown on each individual page.

Is there a way to sort ALL products in the chosen productlist category, before the pagination happens?


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Emil,

You can set the sorting in the query on which the productlist is based, and you can set the sorting on the paragraph settings of the product catalog as well. Why is that not an option?

Best regards
Morten

 
Emil Ryberg
Reply

That isn't a solution in this case. The problem is that it shouldn't sort on just 1 field in the backend.
It needs to sort products first which completes some specific criterias, which is not in any specific product field, custom or non custom.

 
Nuno Aguiar
Reply

Hi Emil,

 

You can set multiple criteria in the paragraph module settings (or even the query). We had this problem in the past and used that approach. In a project of ours we use 4 and even 5 fields. (check dump).

 

You can also change the sorting in the querystring by using sortby=field1,-field2,field3

 

Notice the dash in field2, meaning descending.

 

Best Regards,

Nuno Aguiar

Sorting.JPG
 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Emil,

With the information given, the anwer to your initial question is: No, that is not doable.

As implicitly given in Nunos' example: the information on which you want to perform the sorting, HAS to be in the index. If what you need is more complex than standard, you can make your own indexbuilder that inherits from ie the ProductIndexBuilder, and then stuff it with what-ever you may need. 

Bottom-line is: sortable information has to be in the index.

Best regads
Morten Snedker

Votes for this answer: 1
 
Emil Ryberg
Reply

Alright, thank you for the help.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Guys,

Can this syntax be used in sorting other lists (non-product) based on the new index?

I am having a hard time sorting a list of articles (using Content Index Builder or SQL Index Builder) using multiple criterias (not to mention I have a hard time sorting by one criteria anyway).

Is the syntax similar? I remember another post, where Nuno also had a great contribution, saying that the fields used for sorting need to be named differently and avoid Analyzing them.

Any thoughts on that?

Thanks,

Adrian

 

You must be logged in to post in the forum