Ecommerce Volume Discounts: How to ignore variant

Keith Donnell asked on November 18, 2015 18:20

It appears that volume discounts that you apply to a product appear to only qualify when any single variant hits the minimum threshold. How can we force the system to disregard the variant (i.e. tshirt size)?

For example, I want to offer $2 off each tshirt purchased when 10 or more are purchased. Right now, if I add a Volume Discount with a minimum amount of 10 and value $2, the system requires the customer to add 10 small, 10 medium, or 10 large, etc., to the cart. I want the customer to be able to add 5 small and 5 large and still receive the volume discount.

Correct Answer

Keith Donnell answered on November 19, 2015 20:49

That was the hint I needed, thank you Boris (I actually needed to override the ShoppingCartItemInfoProvider.GetDiscountsInternal method in order to accomplish what I needed). For future reference, here is my custom provider implementation:

using System;
using System.Linq;
using System.Collections.Generic;

using CMS;
using CMS.Ecommerce;
using CMS.Base;


[assembly: RegisterCustomProvider(typeof(CustomShoppingCartItemInfoProvider))]
public class CustomShoppingCartItemInfoProvider : ShoppingCartItemInfoProvider
{
    /// <summary>
    /// Returns list of all discounts which should be applied to the specified shopping cart item.
    /// </summary>
    /// <param name="item">Shopping cart item</param>       
    protected override List<IItemDiscount> GetDiscountsInternal(ShoppingCartItemInfo item)
    {
        // CUSTOM - temporarily set qty of the line item to the total number of any variant in the same parent product
        int? originalQty = null;
        if (item.SKU.IsProductVariant)
        {
            // Save the original quantity so we can restore it when we're done
            originalQty = item.CartItemUnits;
            item.CartItemUnits = item.ShoppingCart.CartItems.Where(i => i.SKU.SKUParentSKUID == item.SKU.SKUParentSKUID).Sum(i => i.CartItemUnits);
        }

        // Get default discounts
        List<IItemDiscount> discounts = base.GetDiscountsInternal(item);

        // Restore the original quantity
        if (originalQty != null)
        {
            item.CartItemUnits = originalQty.Value;
        }

        return discounts;
    }
}
1 votesVote for this answer Unmark Correct answer

Recent Answers


Boris Pocatko answered on November 19, 2015 07:13 (last edited on December 10, 2019 02:30)

You will have to override some internal method. I'd guess you'd have to do it in the "CalculateOrderDiscountInternal" method. You can find an example in the Kentico installation directory, usually in: c:\Program Files (x86)\Kentico\8.2\CodeSamples\App_Code Samples\E-commerce samples\CustomShoppingCartInfoProvider.cs. Another alternative is to use the Order discounts application and to specify it as a special condition (I'd look into the {%ECommerceContext.CurrentShoppingCart.TotalUnits|(identity)GlobalAdministrator%} macro or create a custom macro method if this doesn't work).

1 votesVote for this answer Mark as a Correct answer

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