we are using the SearchFilterHelper to execute the search and the criteria uses CatalogEntrySearchCriteria.DefaultSortOrder (the constants value is _sortorder) which to my understanding should sort the results according to the sort oder that is in the product (Commerce Manager UI sort order field). But if I change the sort order for a product it doesn’t have any effect on the order the results are returned (and I have rebuilt the index) and when looking at the returned properties of a product there is no sort order field.
So shoud it be possible to sort the products according to the sort order visible in the Commerce Manager UI or should this be implemented by us for example by creating a new metafield ProductDisplaySortOrder and use that to order the products?
You can try to parse CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull to SearchFilterHelper.SearchEntries method. This will return full information of catalog entry
Hope this helps.
Hi and thanks for the response.
We are already using the CatalogEntryFull so it is not about that.
I think you can create new SortObject with sort field name as SortOrder instead of using the DefaultSortOrder
SearchSort sortObject = new SearchSort("SortOrder");
And because SortOrder is the meta field, then you cannot access it as a property of product. The meta fields can be accessed through the Entry class API using the ItemAttributes member
Entry entry = CatalogContext.Current.GetCatalogEntry("YourEntryCode", new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
var sortOrder = entry.ItemAttributes["SortOrder"].Value;
Thanks again for the reply.
To me it really looks like that the sort order that is avaiulable in the UI is not actually used or returned in the code. We had already checked the returned properties from the entry.ItemAttributes collection and there we can only see the following properties:
I think in this case you can creat your own meta field and call like "CustomSortOrder", then you can search, sort by your meta field (remember to check "Allow Search" for your meta field).
In your meta class, select your custom meta field and then you can update value for product. I believe that the search result will contain custom meta field when you attach it to meta class
thanks for trying to help, so my original thought was correct.
Maybe you guys could update the Commerce documentation and samples about it unless this is a bug.
I am trying to sort the Product list on Enoteca site but I am unable to find out where and what value I should pass so that the Product list resultant will sorted by "High to Low" and "Low to High price". Can you please give me an idea how can I make it working ?