We are using Catelog Product Model to search products and already had Sort by options with DisplayName and Relavance.
Now we would like to sort the results with Price(Asc & Dsc) wich is with variation. In our case We have developed query with Catelog Product Model,
So until we get the results of query we are not going to get the price of variation.
If anyone achieved this scenario please help us to break it.
Here is some code snippet:
query = query.OrderByDescending(p => p.DisplayName); //Used to sort with Display Name. P->Product Model
We tried with
query = query.OrderByDescending(p => p.GetProductPrice()); which is not effecting the results, because of not having price here.
var results = query.ApplyBestBets().Skip((page - 1) * pageSize).Take(pageSize).Track().GetContentResult();
In that case, you can create your own custom OrderBy method.
In that method you can get all the variants and thne, you can do a FirstOrDefault for price (of all variants under that product) or you can take either max priced variant or the min priced variant. Then sort your product based on that variant price.
If I understand the problem correctly I would solve it by:
SearchClient.Instance.Conventions.ForInstancesOf<ProductModel>().IncludeField(x => x.GetPrice());
query.OrderByDescending(p => p.GetPrice());