Hide menu Last updated: Oct 24 2016
Area: Episerver Commerce Applies to versions: 10.1 and higher
Other versions:

Hiding promotion types

This topic explains how to determine which promotion types appear on the Edit Discount view in Episerver Commerce. To do this, use the PromotionTypeHandler class. Use it to prevent marketers from creating new promotions of those types.

  • DisablePromotions. Disable promotion types. These promotions do not appear in Edit Discount view.
  • EnablePromotions. Enable promotion types.
  • DisableBuiltinPromotions. Disable all built-in promotion types. If this is set, only custom promotions appear in the UI.
  • 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(); } } }

Comments