Simulated discounts



Some background: In some cases I need to call a third-party service which sends entry/order/shipment level discounts (there are not related to any promotions in the system) and then I need to apply these values.

I reviewed RemoveDiscountsActivity and CalculateDiscountsActivity and did the following trick to apply form discount:

foreach (var orderForm in _cartHelper.Cart.OrderForms.ToArray())
    orderForm.Discounts.Add(new OrderFormDiscount
        DiscountName = SimulatedDiscountName, // @SimulatedDiscount
        DiscountValue = discountValue

But the same trick doesnt work for line item discounts. And for shipments discounts I didnt even try.

Maybe someone can help me with it or suggest the better solution.


Jun 16, 2016 13:06

Quick update:

I have successfully founded the way to add the line item discount:

lineItem.Discounts.Add(new LineItemDiscount
    DiscountName = SimulatedLineItemDiscountName, // @SimulatedDiscount:ValueBased
    DiscountAmount = discountValue,
    DiscountValue = discountValue

It stores in database and works with CartValidate and CartPrepare workflows.

But I understood that the trick decribed early for form discounts doesnt work correctly. Form discount is removed from database after CartValidate workflow.

Looking for a solution.

Jun 17, 2016 14:16

As long as there is an @ in the beginning of the name it should not remove the discount.

Jun 20, 2016 10:39

Actually its only partially true.

For instance, for line item discounts the part ":ValueBased" (":PercentageBased") is required.

For form discounts even if discount with name started with "@" it will be deleted because method RemoveGiftPromotionFromOrder from CalculateDiscountActivity removes discounts which are not connected with Episerver promotion. So what I did I imported whole Mediachase.Commerce.Workflow project and changed a little bit RemoveGiftPromotionFromOrder method to avoid removal of discount with specified name.

Edited, Jun 20, 2016 11:35
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.