Loading...
Area: Episerver Commerce
Applies to versions: 10 and higher
Other versions:

Overriding default conventions

Recommendations [hide]

This topic describes indexing conventions for catalog content and how to make changes to the default behavior, in Commerce solutions where the Episerver Search & Navigation-Commerce integration (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 implementation.

public class MyCatalogContentClientConventions : CatalogContentClientConventions 
  {
  }
[ModuleDependency(FindCommerceInitializationModule)]
public class MyCommerceInitializationModule : IConfigurableModule
  {
    public void ConfigureContainer(ServiceConfigurationContext context)
      {
        context.Services.AddSingleton<CatalogContentClientConventions, MyCatalogContentClientConventions>();
      }
    public void Initialize(InitializationEngine context)
      {
      }
    public void Uninitialize(InitializationEngine context)
      {
      }
}

Removing inventories from being indexed

Inventories get indexed for variants by default. The inventories are part of the variant document, and contain information about the inventory in different warehouses.

When the inventory event is triggered, the variant content is re-indexed. By removing the inventories from the variant, the content is not re-indexed on inventory updates.

protected override void ApplyIStockPlacementConventions(TypeConventionBuilder<IStockPlacement> conventionBuilder)
  {
    base.ApplyIStockPlacementConventions(conventionBuilder);
    conventionBuilder
        .ExcludeField(x => x.Inventories());
  }

Removing prices from being indexed

Prices are indexed for variants by default, are part of the variant document, and contain information about the prices for different users and groups.

When a price event is triggered, the variant content is re-indexed. By removing the prices, and default price from the variant, 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());
  }

Applying default 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>());

    ChangeConverterForInstancesOf<Money>(clientConventions, new Json.MoneyConverter());
    ChangeConverterForInstancesOf<MarketId>(clientConventions, new Json.MarketIdConverter());
  }

Applying 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. You can 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());
  }

Applying price conventions

This method allows 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, you can remove this convention.

protected override void ApplyPriceConventions(TypeConventionBuilder<Price> conventionBuilder)
  {
    conventionBuilder
        .ExcludeField(x => x.EntryContent);
  }

Applying stock placement conventions

This method allows for IStockPlacement to be indexed, meaning that inventory records are indexed with the associated content. You can override this method if you want to change which fields are indexed.

protected override void ApplyIStockPlacementConventions(TypeConventionBuilder<IStockPlacement> conventionBuilder)
  {
    conventionBuilder.IncludeField(x => x.Inventories());
  }

Applying 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: Feb 20, 2017

Recommendations [hide]