HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Hiding promotion types

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

How it works

Hiding promotions can be useful in scenarios where you want to prevent merchandisers and marketers from creating new discounts of specific types.

Components mentioned here are available in the EPiServer.Commerce.Marketing namespace.

To hide promotions, use the PromotionTypeHandler class.

  • DisablePromotions. Disable promotion types. This setting will prevent these promotions to appear when editing discounts.
  • EnablePromotions. Enable promotion types.
  • DisableBuiltinPromotions. Disable all built-in promotion types. If this is set, only custom promotions appear in the user interface.
  • GetAllPromotionTypes. Get all of your site's promotion types.

Examples

Disable the BuyQuantityGetFreeItems promotion.

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

Re-enable that promotion.

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

Disable 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();
              }
          }
      }

What’s Next