Hi
Say I have the following active discount types:
Line item discounts
Buy Products for Discount on All Selections
- Buy at least item: 1
- From entries: Product A
- At the follwing discount: 10 % off
Buy Products for Discount on All Selections
- Buy at least item: 1
- From entries: Product B
- At the follwing discount: 25 % off
Buy Products for Discount on All Selections
- Buy at least item: 1
- From entries: Product C
- At the follwing discount: 30 % off
With one of each products the cart now looks something like this:
Product | Quantity | Product placed price | Percentage off and saved amount | Product discount price | Product Total |
Product A | 1 | 769 | 10 % - 76,9 | 692,1 | 692,1 |
Product B | 1 | 1399 | 25 % - 349,75 | 1049,25 | 1049,25 |
Product C | 1 | 999 | 30 % - 299,70 | 699,30 | 699,30 |
I also have another discount which gives 20 % off the entire order if the spent amount is more than 2000 including VAT:
Order discounts
Spend for Discount on Order
- Spend at least: 2000 (incl. VAT)
- Get the follwing discount: 20 % off
Because I always want to provide the best (lowest) possible price I want the 10 % line item discount to be replaced with a 20 % off that item. The products which get 25 % and 30 % off should remain as their discounts are better than the 20 % provided by the order campaign.
I have tried a few different setups, but I am not able to fully acheive what I want:
- If i leave the discounts as explained above and let the order discount have lower priority than the line item discounts, the order discount takes another 20 % off all the discounted products and any other products in the cart.
Money orderDiscountTotal = _orderGroupCalculator.GetOrderDiscountTotal(cart);
This is as expected as it returns the sum of all line items OrderDiscountValue, but it is not what I want.
- If provide a line item discount of 20 % when spent amount is more than 2000 (incl. VAT) another 20 % is taken off all products. Even previously discounted ones. I have tried playing around with sorting order and exclusion rules, but no luck.
- I have also tried finding the entries related to a given promotion, and checking the if the EntryDiscountValue is smaller than OrderDiscountValue.
If I do that, and set the EntryDiscountValue = OrderDiscountValue I sort of get what I want, but I'm unsure how this will affect any other cart totals retrievals down the line fx. when I create summary for order email etc.
Rough code from trying that out:
foreach (ILineItem affectedLineItem in affectedLineItems)
{
var entryDiscountValue = affectedLineItem.GetEntryDiscountValue();
var orderDiscountValue = affectedLineItem.GetOrderDiscountValue();
if (entryDiscountValue < orderDiscountValue)
{
decimal percentage = fulfilledOrderRewardDescriptions.FirstOrDefault().Percentage;
var result = affectedLineItem.PlacedPrice - (affectedLineItem.PlacedPrice - (affectedLineItem.PlacedPrice * percentage / 100));
cart.GetFirstForm().GetAllLineItems().FirstOrDefault(x => x.Code == affectedLineItem.Code).SetEntryDiscountValue(result);
_orderRepository.Save(cart);
}
}
Has anyone had to implement something similar to my use case? Or perhaps someone can point me towards are proper approach?