Try our conversational search powered by Generative AI!

Find: OrderBy Price from variant included by convention in product search document

Vote:
 

Hi,

So I have variant information inclued in Find Product record by convention:

        protected override void ApplyProductContentConventions(EPiServer.Find.ClientConventions.TypeConventionBuilder<ProductContent> conventionBuilder)
        {
            base.ApplyProductContentConventions(conventionBuilder);

            //Add custom field to search index
            conventionBuilder.ExcludeField(x => x.Variations())
                             .IncludeField(x => x.VariationContents()) //Variations
                             .IncludeField(x => x.DefaultImageUrl()) //Default Image Url
                             .IncludeField(x => x.DefaultPrice()) //default price (anonymous)
                             .IncludeField(x => x.Outline()) //The tree hierarchy of the content
                             .IncludeField(x => x.SortOrder());

        }

Now I would like to sort my products by price ascending using a specific variation type.

I tried the following but always get Bad Request I suspects it is because the prices live in the nexted VariationContents.

query = query.OrderBy(product => product.Prices(),
                              priceFieldSelector => priceFieldSelector.UnitPrice.Amount,
                              priceFilterExpression => priceFilterExpression.CustomerPricing.PriceCode.Match(""),
                              EPiServer.Find.Api.SortMissing.Last
                              );

Unsure how to proceed

#200824
Jan 25, 2019 23:30
* 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.