3

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?

1 Answers1

2

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

Jerreck
  • 2,930
  • 3
  • 24
  • 42
  • Discounts that combine other discounts are not really a viable option for us. I was hoping Kentico would already support multiple discounts as they store a single discount applied into a collection. Why would this be done if you can only apply one? Is the only choice at the moment to create our own custom functionality over this? – Nathan Pearce Feb 12 '16 at 11:55
  • Looking at the API in v7, the ShoppingCartInfo property ShoppingCartDiscountCouponID stores a single ID for a discount coupon, which seems to suggest that only a single coupon can be applied to the cart. The COM_SKUDiscountCoupon table also seems to reflect this model. That doesn't mean it's the same in v8, though. I'm installing 8.2 so that we can figure this out :) – Jerreck Feb 12 '16 at 14:24
  • Thanks Jerreck. If I do have to build some custom functionality, I'll try and keep it modular and share it for others. – Nathan Pearce Feb 12 '16 at 14:45
  • What you have looked into does make sense. It is a shame it is not a trivial task though, as I previously thought. Thanks – Nathan Pearce Feb 12 '16 at 16:14