Developer forum

Forum » Ecommerce - Standard features » Product List sorting on frontend

Product List sorting on frontend

Stephen Anthony Jackson
Stephen Anthony Jackson
Reply

I am having trouble finding the correct information on this subject as it seems to have changed over time.

Is the CORRECT format for sorting on frontend in Dynamicweb 9.17  

?SortBy=COLUMN_NAME&SortOrder=ASC|DESC

AND

?SortBy=COLUMN_NAME1,COLUMN_NAME2&SortOrder=ASC|DESC,ASC|DESC

?

I have tried these formats, and they dont have any effect on the sorting of the columns in question, 

For example, I have a "Manufacturer" column, of field type text . 

The query string ?PageSize=100&SortBy=Produsent&SortOrder=DESC OR ASC  does not change the sorting of this column

Hope someone can provide the correct format

Thanks in advance!

//Steve

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Stephen

Yes, sorry about the confusion.

There is the 'old' product catalog AKA the template tag based version and the 'new' product catalog for viewmodels (5 years old). The old one uses the database and the new one uses the Index to search and query products.

The notation you have found is related to the old version.

In the new version (which is used by Swift) you can do this:

Sort ascending: https://swiftdemo.dynamicweb-cms.com/e-bikes/e-mountain-bikes?SortBy=NameForSort

Sort descending: https://swiftdemo.dynamicweb-cms.com/e-bikes/e-mountain-bikes?SortBy=-NameForSort

To sort descending you add a '-' character in front of the field you are sorting by.

The 'NameForSort' is a field in the index that I've defined for sorting as below:

The name you use in querystring is the systemname of the field in the index (not the database or customfield system name).

The field should be non-analyzed. If you mark it as analyzed, the values in the field can be divided into terms resulting in weird sortings. E.g. "my product" will be split into 2 terms 'my' and 'product' and when you sort, it will see both a 'm' starting letter and a 'p' starting letter because the field has 2 terms. And how that works inside Lucene, I do not know. But take-away is to not analyze the fields you want to sort by.

 

 
Stephen Anthony Jackson
Stephen Anthony Jackson
Reply

Thanks Nicolai. 

I see now that the issue was with the system name. I was trying a certain name, and it was a product category field.

So for example, I have a product category which is ProductCategory|Motor|Effekt_kW

I was trying SortBy=-Effekt_kW and -Effekt_kW, but the name has to match exactly the system name in the index (ProductCategory|Motor|Effekt_kW)

It works but it looks very odd in the query string, and it will be a bit of a pain to implement that in the template I think. Should I just create new indexes then with short names which are more user friendly and use those in product list instead? The system name IS effekt_kw, but lucene thinks its ProductCategory|Motor|Effekt_kW. I guess thats cos you can have the same system name in multiple categories

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Stephen

Index field names and database/configuration names are not equal - which can be difficult sometimes, I agree. And yes - we had to give them specific names since we ran into issues with "Width" being both a standard field, custom field and multiple category fields as one example.

It is better to map the fields in the index explicitly in your case if you want a cleaner URL. Also you can better control the analyzed vs non-analyzed part of the issue.

BR Nicolai

 

You must be logged in to post in the forum