Multiple reward descriptions from one promotion processor

Hello, 
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?


Regards,

#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:

    https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2017/4/how-to-add-manual-order-promotion/

    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
            }
        };
        orderForm.Promotions.Add(promotionInformation);
    }

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


    Regards,

    #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