To follow up a thread in Commerce Server forum: How could i sort by property1 ASC and property2 DESC in a catalog search?, I was surpised that one of the basic Commerce Server feature was not understanding.
It’s a common task in e-Commerce to sort a products’ list (or for a category) in different way for different properties, ie property1 ascending and property2 descending and keep the paging stuck to those properties ordering.
The Ravi’s solution was to use a dataview. But the main issue here is that you can only sort the result returning by the CatalogSearch! What append if you have multiple pages? And on top of that, the poor performance to sort with a DataView…
To achieve this, you simply need to use the common search CatalogSearch class. You just have to surround the propery with sqaure brackets and then the order way:
CatalogSearch catalogSearch = catalogContext.GetCatalogSearch(); catalogSearch.CatalogNames = "MyCatalog"; catalogSearch.SearchOptions.ClassTypes = CatalogClassTypes.ProductFamilyClass; catalogSearch.SearchOptions.PropertiesToReturn = "ProductId, cy_list_price"; catalogSearch.CategoriesClause = "CategoryName = 'CatId"; catalogSearch.SqlWhereClause = "Display = 'OK'"; catalogSearch.SearchOptions.SortProperty = "[ProductId]ASC, [cy_list_price]DESC";
Be careful, it’s very important to haven’t got any space between the ordering way and the right square bracket.
For information, our Commerce Server developer senior, Anoir, have already wrote a post about it (in french ): Recherche d’un produit avec plusieurs colonnes de tris différenciés in the Altima’s blog.