Multiple reward descriptions from one promotion processor


I need to have different discounts applied to lineitems based on various rules. However, it seems that promotion processor allows only one reward description to be created. Is there any provisions to have multiple?

For example, I want lineItem1 to get 10% discount and lineitem2 to get 20% percent discount. 
I cannot use multiple promotion processors, because these percentages are dynamic. 

What is the best way to do this?


#184691 Nov 02, 2017 11:04

    I'm looking for a ways to do this, and fouhnd that you can add manual fromotion as described in this thread:

    private static void AddDiscount(
        IOrderForm orderForm,
        string lineItemCode,
        decimal discountValue,
        string discountName)
        var promotionInformation = new PromotionInformation
            Name = discountName,
            Description = discountName,
            DiscountType = EPiServer.Commerce.Marketing.DiscountType.Manual,
            Entries = new List<PromotionInformationEntry>
                new PromotionInformationEntry
                    EntryCode = lineItemCode,
                    SavedAmount = discountValue
            OrderForm = new PromotionInformationOrderForm
                SavedAmount = 0

    However, this doesn't seem to do anything in version I use (9.24). What could be wrong?

    #184759 Nov 03, 2017 7:39
  • Member since: 2016

    Are you running _promotionEngine.Run after you've added your manual promotion to the orderform?

    #184760 Nov 03, 2017 8:38

    Currenly, I'm adding this inside PromotionProcessor as a workaround to have multiple discounts from one promotion. But it doesn't seem to work.

    #184761 Nov 03, 2017 8:44
  • Member since: 2016

    Or actually it seems that you need to run cart.ApplyDiscounts(). From what I can see, _promotionEngine.Run doesn't care about manual discounts in the orderForm.Promotions, but if you run cart.ApplyDiscounts() it will apply them as well.

    cart.ApplyDiscounts() will in itself run _promotionEngine.Run and you can provide the PromotionEngineSettings to ApplyDiscounts as well.

    #184762 Nov 03, 2017 8:44
  • Member since: 2016

    Ah, no, then I see why it wouldn't work. PromotionInformation is just a describing class of a seemingly applied promotion. But if you want to add a manual promotion by first creating the PromotionInformation, you still need to actually do something to apply them. By themselves PromotionInformations do nothing.

    Therefore I'm not sure you can actually set your manual PromotionInformation from inside a processor. Since the promotion engine runs the processor, you have gone beyond the point where it would take care of manual promotions. So it would never be applied price wise (to the discountedPrice on any lineitem, where the actual discount values are stored after being calculated by the whole promotion engine schbang).

    The flow as I see it (haven't tested it, just theorizing):

    1. Create PromotionInformation with type Manual
    2. Add them to the orderform by form.Promotions.Add
    3. Run IOrderGroupExtensions.ApplyDiscounts, that in turn will
      1. Store away the manual discounts existing on all the orderforms
      2. Runs promotionEngine.Run, which itself will remove all the Promotions from the orderform (because they are to be re-evaluated)
      3. Take the stored manual discounts and apply them

    So creating PromotionInformations outside of this flow won't impact the actual prices.

    #184764 Nov 03, 2017 8:54

    That seems wrong, because we wanted to use new promotion engine specifically to avoid such mess. It looked very promising until we stumbled upon this inability to apply multiple discounts.

    Also, I looked at Episrever code and your solution also look as if it wont work. ApplyDiscounts look like this:

        public static IEnumerable<RewardDescription> ApplyDiscounts(this IOrderGroup orderGroup, IPromotionEngine promotionEngine, PromotionEngineSettings settings)
          return promotionEngine.Run(orderGroup, settings);


    #184765 Nov 03, 2017 9:07
  • Member since: 2016

    Ah, perhaps I'm actually talking about something that was implemented after 9.24 :( 

    ApplyDiscounts in 11.2 looks like this:

    So I guess somewhere along the line of 9.24 to 11.2 manual discounts were implemented in the new promotion system. Or there is some other way of enabling/using it.

    #184766 Nov 03, 2017 9:12

    Yes, it seems to be different in the version I use. However,  this still would be no help to me because I need this discount to be proceesed before some others. 

    #184770 Nov 03, 2017 10:38

    Hi Joel

    I tried the above logic by adding AddDiscount method to my Custom Promotion Processor, and then in the processor, i'm trying not to calculate discount, so that its only handled by ApplyDiscounts method. However, my items are getting double discounts. Plus, each refresh of the cart applies the double discounts again, until the total price on line item becomes 0.

    Also, i've added logic in CanBefulfilled method to not apply discounts when condition product isn't in cart and that part works. But once i have it in cart and my discount applies, if i remove the condition item, the discount still stays. It shouldn't. How and where can i handle this if I'm using above ApplyDiscounts logic?

    #185648 Nov 28, 2017 16:44
  • Member since: 2016


    Which ApplyDiscounts logic are you talking about? ApplyDiscounts is just an extension method to IOrderGroup that will run _promotionEngine.Run().

    What I'm saying in the above answer is that the use case Giedrius is talking about cannot be solved with Manual Promotions. And in order to run manual promotions you need to run cart.ApplyDiscounts instead of _promotionEngine.Run because it's in that method it will take into consideration the manual promotions existing on the orderform :)

    I'm not sure where the problems you're having are originating, it would help if you pasted your processor code here so I can take a look at what you are doing.

    #185654 Nov 29, 2017 2:37
First   1 2   Last