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

Hiding promotion types

Recommendations [hide]

This topic explains how to determine which promotion types appear on the Edit Discount view in the Episerver Commerce 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();
          }
      }
  }
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 24, 2016

Recommendations [hide]