HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Exclude a market filter from "filter for visitor"

Describes how to exclude a market filter from the "filter for visitor" function in Optimizely Customized Commerce.

By default, when installing EPiServer.Find.Commerce, EntryContentBase types do not get hits in the Optimizely Search & Navigation index until all documents are reindexed. To override this functionality, follow this step.

In the templates, inside the InitializationModule class, re-register all instances that implement the IFilterForVisitor interface, except for an instance of FilterCurrentMarketForVisitor.

public void ConfigureContainer(ServiceConfigurationContext context)
      {
        SetupFilterForVisitor(context);
        context.Services.Configure(c => c.For<ICurrentMarket>().Singleton().Use<MarketStorage>());
      }
    
    private void SetupFilterForVisitor(ServiceConfigurationContext context)
      {
        var customFilterForVisitors = context.Container.GetAllInstances<IFilterForVisitor>().Where(x => !(x is FilterCurrentMarketForVisitor));
        context.Container.EjectAllInstancesOf<IFilterForVisitor>();
        foreach (var instance in customFilterForVisitors)
          {
            context.Container.Inject(instance);
          }
      }