Search code examples
kenticodiscounts

Kentico - Adding multiple discounts


I'm using Kentico version 8.2, and am trying to allow a user to enter multiple coupons. In the ECommerceContext.CurrentShoppingCart object you have a ShoppingCartCouponCode that you can set. This then adds this coupon to the Discounts collection on that object.

If I change the ShoppingCartCouponCode to something else, then the Discount collection gets recreated with a single item of the new discount again, and loses the old discount.

If I store a copy of the discount collection, then apply the new coupon entered, and then append the copied collection to the new generated Discount collection then that works for only a couple of discounts. I am concerned that doing it this way will cause issues elsewhere.

So has anyone implemented this functionality before and how did/would you go about it?


Solution

  • EDIT: Although it seems like Product Coupons should allow you to do this, they don't work quite the way you would think. When a Product Coupon is applied to the cart, the ShoppingCartDiscountCouponID field for that cart's record in COM_ShoppingCart is updated to include a foreign key reference to the ID of discount coupon in COM_DiscountCoupon. So there can definitely be only one Product Coupon applied to the cart at any one time.

    So instead of being a discount on a particular product, they seem to be more like flags that allow you to apply discounts to the entire cart if a particular product is in the cart and the correct coupon code is entered.

    However, that doesn't mean we can't do some customization to achieve this affect ourselves. Our first step will be to change the ShoppingCartContent control in CMSModules > Ecommerce > Controls > ShoppingCart to allow multiple coupon codes to be entered. That's the easy part.

    The second part is to change how discounts and carts are associated. This could require modifying Kentico's system tables, so do so at your own risk. You'll basically want to decouple foreign key reference from the COM_ShoppignCart table and create a many-to-many relationship between carts and discounts. Personally, I would leave the system tables and API alone and just create another custom table that mapped CartIDs to DiscountIDs (you will probably have to do the same with Orders, too since cart data is applied to order data when an order is created).

    The last part is changing how discounts are actually calculated. Earlier I suggested creating a custom DiscountCouponInfoProvider. Turns out, what you actually want to do is create a custom ShoppingCartInfoProvider and override one of the following methods:

    • CalculateOrderDiscount()
    • CalculateItemsDiscount()

    I apologize if this isn't descriptive enough, but this will be a significant modification to how Kentico handles Product Coupons, so I don't have a lot of time to get into specifics. However, I would estimate that it would take a least a few weeks to accomplish.


    old answer

    Hmm, you could create discounts that represent combinations of two or more discounts and apply those if a user selects the right combination.

    Or, what I would prefer if I had the time to build it, would be to create a custom DiscountCouponInfoProvider that changes how discounts are applied.M