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 https://github.com/x2find/Nested2Find which might work (but I haven't tried this yet).
Hopefully this is a simple question for someone :)
In theory, it won't work, as decimal was not supported by current EPiFind (or ElasticSearch)
Thanks for a reply - at least I won't burn any more time on a dead end :)
If I was desperate it would be interesting to know if simply modifying the indexing to round prices to ints would allow sorting.
My current workaround is to use "Double" in my index, sorting worked as expected.
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./Henrik
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.ValidUntil.Exists() | price.ValidUntil.GreaterThan(currentDate))
& (price.MarketId.Value.Match(currentMarket.MarketId.Value) | price.MarketId.Value.Match(string.Empty)))
Great!I really appreciate the positive feedback. #happydev :-)/Henrik