Try our conversational search powered by Generative AI!

OrderBy price commerce results


Have Googled and browsed around some topics but not sure I have found a conclusive answer to what I thought should be a simple question:

Can I sort Find results of commerce variations by price?

As prices are nested objects I can't see a way to OrderBy them natively with the Find API.. I have also looked at which might work (but I haven't tried this yet).

Hopefully this is a simple question for someone :)


May 31, 2016 13:46

In theory, it won't work, as decimal was not supported by current EPiFind (or ElasticSearch)

Jun 03, 2016 5:24

Thanks for a reply - at least I won't burn any more time on a dead end :)

Jun 06, 2016 4:27

If I was desperate it would be interesting to know if simply modifying the indexing to round prices to ints would allow sorting.

Jun 06, 2016 4:29

My current workaround is to use "Double" in my index, sorting worked as expected. 

Jun 06, 2016 5:40

As of Find 12 you can sort on a decimal property. As for nested you currently have to specify:

.OrderBy(x => x.Players, p => p.Salary, null /* optional filter */, SortMissing.First, SortOrder.Ascending, SortMode.Min)

where SortMode.Mix/Max/Avg/Sum specifies if you want sorting to be done for the minimum, maximum, average or sum of the nested object values.


Jun 09, 2016 8:37

Just to report back, since Episerver.Find.Commerce just got updated to support Find v12, I just gave this price sorting a go and it works perfectly!

In our case we actually have a complex nested filter for determining a customer's price - and I've used this code here which behaves exactly how we intended:

query.OrderByDescending(v => v.Prices(), p => p.UnitPrice.Amount, price =>
                    price.CustomerPricing.PriceTypeId.Match(CustomerPricing.PriceType.UserName) & price.CustomerPricing.PriceCode.Match(accountNumber)
                    | price.CustomerPricing.PriceTypeId.Match(CustomerPricing.PriceType.PriceGroup) & price.CustomerPricing.PriceCode.Match(priceGroup)
                & price.ValidFrom.LessThan(currentDate)
                & (price.ValidUntil.Exists() | price.ValidUntil.GreaterThan(currentDate))
                & price.UnitPrice.Currency.CurrencyCode.Match(customerContact.PreferredCurrency)
                & (price.MarketId.Value.Match(currentMarket.MarketId.Value) | price.MarketId.Value.Match(string.Empty)))
Jun 14, 2016 3:30


I really appreciate the positive feedback. #happydev :-)


Jun 14, 2016 8:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.