Promotions [Beta]: Different discount percent for each line item.

Member since: 2012

I have EPiServer.Commerce 9.19.0 installed (probably promotions are not Beta anymore). I have a requirement to be able to apply different percentage discount for each line item. Basically, I am storing discount % in line item metadata.

Now I created new EntryPromotion and entry promotion processor. In the evaluate method I am loading all line items which has discount % stored in metadata and want to apply those, but when creating RewardDescription there is no way to set discount on each line item - only one value for all line items:

protected override RewardDescription Evaluate(
    AdditionalItemDiscountPromoData promotionData,
    PromotionProcessorContext context)
{
    var orderForm = context.OrderForm;
    var cart = context.OrderGroup as Cart;
    if (cart == null)
    {
        return NoReward(promotionData);
    }
 
    var lineItems = cart.GetAllLineItems().Where(HasDiscount);
 
    var priceEntries = new List();
    foreach (var lineItem in lineItems)
    {
        var discount = // <-- discount to apply to single item
			(decimal) (item.Properties[Constants.AdditionalDiscountPercentMetaField] ?? 0.0m);
		priceEntries.Add(new PriceEntry(lineItem));
	}
	
	var discountToAllItems = 10;

	return RewardDescription.CreatePercentageReward(
		FulfillmentStatus.Fulfilled,
		new[] { CreateRedemptionDescription(new AffectedEntries(priceEntries)) },
		promotionData,
		discountToAllItems, // <-- only one discount value can be applied to all items but require separate for each item
		description: $"{promotionData.DiscountPercent} % discount applied to line items");
}

Is there some other way to apply such promotion?

#151620 Edited, Aug 01, 2016 9:43
  • Member since: 2008

    Maybe doing them as separate redemptions is technically feasible and maybe even the logically correct way to handle it? Is there any condition to be met to qualify for the promotion or is that already determined elsewhere when the discount percentage is set on the line item? What determines the discount? Any chance it is more like a customer group specific price and should be handled as such instead of a promotion?

    #151656 Aug 02, 2016 19:59
  • Member since: 2012

    I have a special page for customer support staff where they can set discounts onto customer carts - for the whole cart and for separate items.

    I made it to work by creating custom EntryPromotion where an editor can set discount percent on the promotion. So editor can create several promotions with predefined discount percents. On my support staff page, I allow choosing one of the defined promotion. The only disadvantage is that you have to create all possible promotion discount % upfront.

    #151658 Aug 03, 2016 8:22
  • Member since: 2012

    I am not sure i see the need for having a promotion for this at all.

    Do they really add discounts on the carts and not on the purchase orders?

    In either case, why can't customer support discounts be deducted directly from the prices?

    My first try would be to change how the lineitem total is calculated http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-Commerce/9/Orders/calculating-orders/

    Unless you actually need some of the promotion functionality like priority or excluding other promotions?

    #151806 Aug 07, 2016 20:39
  • Member since: 2012

    Yes, there is such need. The use case is: Customer calls Support and asks some questions about the product. The customer might need the same product but with a different color, for example. Support staff gives a discount for the item because they do not have requested color.

    #151818 Aug 08, 2016 8:39
  • Member since: 2008

    IIRC that customer support scenario is supported in commerce manager for both old and new promotion system. I don't remember the details of the implementation but I think it should be possible to mimic if you want to handle it by other means than commerce manager.

    #151842 Aug 08, 2016 15:25
  • Member since: 2011

    Yes, CM supports both automatic and manually-set discounts, in both old and new promotion system. The order manager can simply edit the price of a lineitem to set the discount manually.

    #151848 Aug 08, 2016 16:18
  • Member since: 2012

    But the supported scenario is for orders not carts is it not?

    Can you describe your scenario in more detail Maris?

    Does customer support create the purchase order?

    Are customers allowed to modify their carts after customer service have added the discount? What happens if they remove that lineitem and later add it again?

    #152027 Aug 12, 2016 17:43
  • Member since: 2012

    Erik, the scenario is for Carts and customer support do not create purchase orders. Also, support does not have access to Commerce Manger - they have access only to a specific page where they can do what I described. And customers can add more products if they want after support applied discounts and they can remove items with discounts then they will loose discount.

    But this issue is fixed as described in my answer. :)

    #152625 Aug 26, 2016 12:35