Hide menu Last updated: Nov 30 2016
Area: Episerver Commerce Applies to versions: 10.1.0 and higher
Other versions:

Excluding products from promotions

This topic explains how to configure a filter to exclude a product from the promotion engine. Such products are ignored when evaluating promotions and applying discounts.

Here is a sample use case: while promotions on sneakers may be enacted from time to time, you never want the Faded Glory Mens Canvas Slip-On Shoe to receive a discount or to be included in the discount-related events (such as Buy at least X items...Get the following discount).

To exclude products from the promotion engine, implement the IEntryFilter. In most cases, you can use the EntryFilterSettings class to configure the default implementation. If that does not meet your needs, create your own IEntryFilter implementation.

How it works

The default implementation of IEntryFilter uses the EntryFilterSettings class to implement the Filter method. If using that implementation, you only need to add filters to the instance of EntryFilterSettings. The following example illustrates various ways to configure the settings.

Examples

Add filters when a site is initialized. 

If you want the filters to work on the front end and the back end site, you must configure them on both sites

namespace EPiServer.Reference.Commerce.Site.Infrastructure
{
    [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class SiteInitialization : IConfigurableModule
    {
       public void Initialize(InitializationEngine context)
       {
           SetupExcludedPromotionEntries(context);
       }
public void ConfigureContainer(ServiceConfigurationContext context) { }
public void Uninitialize(InitializationEngine context)
{
}
private void SetupExcludedPromotionEntries(InitializationEngine context) { var filterSettings = context.Locate.Advanced.GetInstance<EntryFilterSettings>(); filterSettings.ClearFilters(); //Add filter predicates for a whole content type. filterSettings.AddFilter<TypeThatShouldNeverBeIncluded>(x => false); //Add filter predicates based on any property of the content type, including implemented interfaces. filterSettings.AddFilter<IInterfaceThatCanBeImplementedToDetermineExclusion>(x => !x.ShouldBeExcluded); //Add filter predicates based on meta fields that are not part of the content type models, e.g. if the field is dynamically added to entries in an import or integration. filterSettings.AddFilter<EntryContentBase>(x => !(bool)(x["ShouldBeExcludedPromotionMetaField"] ?? false)); //Add filter predicates base on codes like below. var ExcludingCodes = new string[] { "SKU-36127195", "SKU-39850363", "SKU-39101253" }; filterSettings.AddFilter<EntryContentBase>(x => !ExcludingCodes.Contains(x.Code)); } } }

Comments