When indexing content using Commerce Connect conventions and extension methods. Some of us tend to use the following:
public static class CommerceExtensions
{
public static string MyExtensionProperty(this VariationContent variation)
{
return "MyTest";
}
}
public class SiteCatalogContentClientConventions : CatalogContentClientConventions
{
public override void ApplyConventions(IClientConventions clientConventions)
{
base.ApplyConventions(clientConventions);
SearchClient.Instance.Conventions.ForType<VariationContent>().IncludeField(p => p.BrandName());
}
}
The above doesn't work as ForType is applied to VariationContent only but not the inherited class for example: FashionVariation
Use ForInstancesOf method instead as it is applied to inherited class:
public override void ApplyConventions(IClientConventions clientConventions)
{
base.ApplyConventions(clientConventions);
clientConventions.ForInstancesOf<FashionVariant>().IncludeField(x => x.MyExtensionProperty
());
}
Please sign in to leave a comment.