Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

Always provide best possible item price from combination of discounts

$
0
0

Hi

Say I have the following active discount types:

Line item discounts

  1. Buy Products for Discount on All Selections

    • Buy at least item: 1
    • From entries: Product A
    • At the follwing discount: 10 % off
  2. Buy Products for Discount on All Selections

    • Buy at least item: 1
    • From entries: Product B
    • At the follwing discount: 25 % off
  3. 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:

ProductQuantityProduct placed pricePercentage off and saved amountProduct discount priceProduct Total
Product A176910 % - 76,9692,1692,1
Product B1139925 % - 349,751049,251049,25
Product C199930 % - 299,70699,30699,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

  1. 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?


Viewing all articles
Browse latest Browse all 6894