"Early" Discount in ShopingCart

B. Todd Oakley asked on February 16, 2015 22:38

We are a membership-heavy Zoo in the US. One of our annual marketing campaigns is to provide a discounted membership rate for new members, to a select target audience. There are only two out of six membership products that will be discounted.

The potential member comes through a landing page w/ lastname and "priority code" fields that validate against a custom table of all targeted customers.

My plan is to use Coupon Codes, with absolute discounts for the specific products, but I don't want the user to see the coupon code or have to manually enter it on the Cart page. I would like to put the coupon code in their "cart" when they are authenticated on that landing page. But the ShoppingCart seems to not exist at that point.

Does anyone have any suggestions? Or do you need me to explain it better? BTW, we are on 7.0.53.

Thanks in advance!

Recent Answers

Joshua Adams answered on February 17, 2015 16:12

At first glance, it would seem that customizing the cart may be the best route. Maybe you could create a table to store the associations between discount codes and the membership products, and through your custom code, attach them where necessary. Maybe also include a start date and end date that you would check as well so that you could manage everything in that table and not have to maintain the products as much.

0 votesVote for this answer Mark as a Correct answer

Josef Dvorak answered on March 17, 2015 12:49

Hello Todd,

Using the Discount coupon indeed sounds like the easiest approach in this case. The shopping cart is created any time a new visitor arrives at the site. CMS.Ecommerce.ECommerceContext.CurrentShoppingCart always initializes into an empty shopping cart object whenever it detects it is currently null. This means you can simply add the discount coupon to it via API and it will apply later when the customer adds anything to it:

DiscountCouponInfo coupon = DiscountCouponInfoProvider.GetDiscountCouponInfo("aaCoupon", CurrentSiteName);
if (coupon != null)
    ECommerceContext.CurrentShoppingCart.ShoppingCartDiscountCouponID = coupon.DiscountCouponID;

The only issue you will need to overcome is that Kentico removes the coupon upon login. The coupon code is considered a private information, so Kentico clears it any time the ownership of the shopping cart changes. You can preserve the discount coupon by implementing this Custom Info Provider:

public class CustomShoppingCartInfoProvider : ShoppingCartInfoProvider
    protected override void ClearShoppingCartPrivateDataInternal(ShoppingCartInfo cartObj)
        int discountCouponID = (cartObj != null) ? cartObj.ShoppingCartDiscountCouponID : 0;


        cartObj.ShoppingCartDiscountCouponID = discountCouponID;

This however is not an issue if the customer registers during checkout, so you can skip this part if the discount will be available only to a completely new users.

0 votesVote for this answer Mark as a Correct answer

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