Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Hide promotion types

Describes how to determine which promotion types appear on the Edit Discount view in the Optimizely Commerce Connect user interface for managing campaigns and discounts (promotions).

Hide promotions to prevent merchandisers and marketers from creating discounts of specific types.

Classes in this topic are available in the following namespace:

  • EPiServer.Commerce.Marketing

To hide promotions, use the PromotionTypeHandler class.

  • DisablePromotions – Disables promotion types. This setting prevents the promotions from being displayed when editing discounts.
  • EnablePromotions – Enables promotion types.
  • DisableBuiltinPromotions – Disables built-in promotion types. When set, only custom promotions appear in the user interface.
  • GetAllPromotionTypes – Gets all promotion types for your site.

The following example disables the BuyQuantityGetFreeItems promotion:

var promotionTypeHandler = ServiceLocator.Current.GetInstance<PromotionTypeHandler>();
promotionTypeHandler.DisablePromotions(new[] { typeof(BuyQuantityGetFreeItems) });

The following example re-enables that promotion:

promotionTypeHandler.EnablePromotions(new[] { typeof(BuyQuantityGetFreeItems) });

The following example disables all built-in promotion types when a site is initialized:

namespace EPiServer.Commerce.Sample.Business.Initialization {
  [ModuleDependency(typeof (EPiServer.Commerce.Initialization.InitializationModule))]
  public class InitializationModule: IConfigurableModule {
    public void Initialize(InitializationEngine context) {
      DisablePromotionTypes(context);
    }

    public void Uninitialize(InitializationEngine context) {}

    public void ConfigureContainer(ServiceConfigurationContext context) {}

    private void DisablePromotionTypes(InitializationEngine context) {
      var promotionTypeHandler = context.Locate.Advanced.GetInstance<PromotionTypeHandler>();

      // To disable all built-in promotion types
      promotionTypeHandler.DisableBuiltinPromotions();
    }
  }
}