Expired discounts and shopping cart recalculation

Mariia Hrytsai asked on March 31, 2016 09:22

There is the following situation. We have existing paid order. We should allow user to update units amount of order items and return extra money paid for customer. But in this case we should recalculate all prices and discounts that were applied to order. So if discount was valid at the order date, but now when we perform this operation, it is not valid, we should still have this discount applied as it was valid at the date of the order Is it possible to change order items units and recalculate order price programatically, but the condition is that all the discounts that were previously applied to the order, even if they are currently expired, retained for this order and total discount amount was recalculated for new total price.

I considered to customuize GetDiscountsInternal method of DiscountInfoProvider class but it looks quite complicated to achieve my goal. Any other suggestions would be appreciated.

Thanks in advance.

Recent Answers

Dawid Jachnik answered on March 31, 2016 12:16


I think is a good solution, but you need to sort out only these discounts which were availble on order time. I think you should check the full stack trace how discount are applied, maybe somewhere valid time of discount is checked again. Here's the documentation of cuztomization Buy X Get X discounts maybe it will help you.

3 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on March 31, 2016 19:20


Actually customizing that would be a good direction if you need to re-apply the discount. You could do something like below. Note you need to first pull from the base call, so you get all the discounts to apply that are currently active, then you can pass that to another function where you could then look at expired discounts that should still be valid and add / edit the discounts applied.

protected override List<IItemDiscount> GetDiscountsInternal(ShoppingCartItemInfo item)
    List<IItemDiscount> discounts = base.GetDiscountsInternal(item);
    discounts = figureOut(discounts, item);
    return discounts;

Hope that helps.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.