Overriding default conventions
This topic describes the indexing conventions for catalog content and how to make changes to the default behavior, in Commerce solutions where the Find search provider EPiServer.Find.Commerce is used.
Catalog content client conventions
To change default behavior, create a new class to override the conventions that are applied. The following example shows what class to inherit from, and how to register your implemenatation.
[ServiceConfiguration(ServiceType = typeof(CatalogContentClientConventions))]
public class MyCatalogContentClientConventions : CatalogContentClientConventions
{
}
Remove inventories from being indexed
Inventories get indexed for variations by default. The inventories are part of the variation document, and contain information about the inventory in different warehouses.
When the inventory event is trigged, the variation content is re-indexed. By removing the inventories from the variation, the content is not re-indexed on inventory updates.
protected override void ApplyIStockPlacementConventions(
TypeConventionBuilder<IStockPlacement> conventionBuilder)
{
base.ApplyIStockPlacementConventions(conventionBuilder);
conventionBuilder
.ExcludeField(x => x.Inventories());
}
Remove prices from being indexed
Prices are indexed for variations by default, are part of the variation document, and contain information about prices for different users and groups.
When a price event is trigged, the variation content is re-indexed. By removing the prices, and default price from the variation, the content is not re-indexed on price updates.
protected override void ApplyPricingConventions(
TypeConventionBuilder<IPricing> conventionBuilder)
{
base.ApplyPricingConventions(conventionBuilder);
conventionBuilder
.ExcludeField(x => x.DefaultPrice())
.ExcludeField(x => x.Prices());
}
Apply conventions
This method applies the default conventions. If you want to make a change, override this method, or any of the submethods, and add or remove conventions you need.
public override void ApplyConventions(IClientConventions clientConventions)
{
ApplyPriceConventions(clientConventions.ForInstancesOf<Price>());
ApplyPricingConventions(clientConventions.ForInstancesOf<IPricing>());
ApplyIStockPlacementConventions(clientConventions.ForInstancesOf<IStockPlacement>());
ApplyProductContentConventions(clientConventions.ForInstancesOf<ProductContent>());
ApplyAssociationConventions(clientConventions.ForInstancesOf<IAssociating>());
ApplyCustomerPricingConventions(clientConventions.ForInstancesOf<CustomerPricing>());
ApplyNodeRelationsConventions(clientConventions.ForInstancesOf<CatalogContentBase>());
ApplyEntryContentConventions(clientConventions.ForInstancesOf<EntryContentBase>());
ApplyBundleContentConventions(clientConventions.ForInstancesOf<BundleContent>());
ApplyPackageContentConventions(clientConventions.ForInstancesOf<PackageContent>());
ApplyCommerceMediaConventions(clientConventions.ForInstancesOf<CommerceMedia>());
ChangeConverterForInstancesOf<Money>(clientConventions, new Json.MoneyConverter());
ChangeConverterForInstancesOf<MarketId>(clientConventions, new Json.MarketIdConverter());
}
Apply pricing conventions
This method allows for IPricing to be indexed, meaning that the default price and all other prices are indexed with the associated content. Override this method if you want to change which fields are indexed.
protected override void ApplyPricingConventions(
TypeConventionBuilder<IPricing> conventionBuilder)
{
conventionBuilder
.IncludeField(x => x.DefaultPrice())
.IncludeField(x => x.Prices());
}
Apply price conventions
This method excludes the EntryContent field from the Price object when indexing. Leave this field excluded if you are indexing prices. If you are not indexing prices, remove this convention.
protected override void ApplyPriceConventions(
TypeConventionBuilder<Price> conventionBuilder)
{
conventionBuilder
.ExcludeField(x => x.EntryContent);
}
Apply stock placement conventions
This method allows IStockPlacement to be indexed, meaning that inventory records are indexed with the associated content. Override this method if you want to change which fields are indexed.
protected override void ApplyIStockPlacementConventions(
TypeConventionBuilder<IStockPlacement> conventionBuilder)
{
conventionBuilder.IncludeField(x => x.Inventories());
}
Apply customer pricing conventions
This method allows for CustomerPricing objects to be properly indexed. If you are indexing prices, leave this convention as-is. If you are not indexing prices, remove this convention.
protected override void ApplyCustomerPricingConventions(
TypeConventionBuilder<CustomerPricing> conventionBuilder)
{
base.ApplyCustomerPricingConventions(conventionBuilder);
}
Do you find this information helpful? Please log in to provide feedback.
Last updated: Nov 03, 2015