Coupon for first-time buyers

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Coupon for first-time buyers

Post by wave_werks » Mon May 18, 2009 12:40 pm

Hello,

I've seen several posts throughout the forums asking for a way to allow customers to come to an AC7 website and make a purchase without having previously shopped on the website. The only requirement for this would be to allow the creation of a coupon that does not need the customer to be in a group since by default new customers are not part of any group when they create their account. However, I have not seen an answer to any of these requests with a working solution.

Here's a practical example of what we need:
We advertise in on the web, in magazines, on postcards & flyers, and on posters. Many of our advertisements have coupon codes for potential customers to use which offer them 10% off of purchases in specific categories. For example, we just advertised for 1 month on MySpace.com offering 10% off of all CD Duplication orders by using one of our coupon codes during checkout. This ad was seen by upwards of 500,000 people. Now, when people come to our website they cannot use the coupon because they have not previously purchased from us and are not part of a "group". We are now forced to manually add them to a "customers" group after explaining to all of them that they must first setup an account and then email us with the address they used to sign up for the account. This is a very, very tedious process and will take far to much time to continue each and every month that we offer these discount codes. The idea here is to invite new business with the discount code and make it seamless for them to make their purchase. I can tell you from several years with another ecommerce solution that this is a HUGE drawback to the current coupon system.

So, how can we setup a coupon so that anyone, without being part of a group, can use our coupon codes to receive their discount.

Next, is there a way to keep certain groups from being allowed to use these "non-group" coupons? We have some customers that receive 10% or 15% off of all items and we do not want to allow them to use the additional coupon codes.

Thanks for your help!
- Jeff
Wave Werks

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Coupon for first-time buyers

Post by mazhar » Tue May 19, 2009 4:34 am

First you can create a discount for order with desired discount amount and can be used only once by a customer. Then you need to do following things

1- Send an Email to people with a link to your website page with encoded coupon code. In order to automate this process you may create some Email template and then write some code to send Email manually to people. Reading following thread will help you
viewtopic.php?f=47&t=8575

2- Now edit your Global.asax file and add following method to it

Code: Select all

 protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    { 
        string couponCode = Request.QueryString["CouponCode"];
        if(!string.IsNullOrEmpty(couponCode))
        Session["CouponCode"] = couponCode;
    }
After this mod you application will look for coupon code in URL against each request and will store it in session if found.

3- Now edit OnePageCheckout.ascx.cs file and add following method to it

Code: Select all

private void ApplyCoupon(string couponCode)
    {
        if (String.IsNullOrEmpty(couponCode))
            return;
        Coupon coupon = CouponDataSource.LoadForCouponCode(couponCode);
        String couponValidityMessage = String.Empty;
        if (coupon != null)
        {
            if (!CouponCalculator.IsCouponAlreadyUsed(Token.Instance.User.Basket, coupon))
            {
                if (CouponCalculator.IsCouponValid(Token.Instance.User.Basket, coupon, out couponValidityMessage))
                {
                    Basket basket = Token.Instance.User.Basket;
                    BasketCoupon recentCoupon = new BasketCoupon(Token.Instance.UserId, coupon.CouponId);
                    basket.BasketCoupons.Add(recentCoupon);

                    // APPLY COUPON COMBINE RULE
                    //THE RULE:
                    //If most recently applied coupon is marked "do not combine", then all previously
                    //entered coupons must be removed from basket.

                    //If most recently applied coupon is marked "combine", then remove any applied
                    //coupon that is marked "do not combine".  (Logically, in this instance there
                    //could be at most one other coupon of this type...)
                    string previousCouponsRemoved = "";

                    if (recentCoupon.Coupon.AllowCombine)
                    {
                        //IF ALLOW COMBINE, REMOVE ALL PREVIOUS NOCOMBINE COUPONS
                        for (int i = (basket.BasketCoupons.Count - 1); i >= 0; i--)
                        {
                            if (!basket.BasketCoupons[i].Coupon.AllowCombine)
                            {
                                if (previousCouponsRemoved.Length > 0)
                                {
                                    previousCouponsRemoved += "," + basket.BasketCoupons[i].Coupon.Name;
                                }
                                else
                                {
                                    previousCouponsRemoved = basket.BasketCoupons[i].Coupon.Name;
                                }

                                basket.BasketCoupons.DeleteAt(i);
                            }
                        }
                    }
                    else
                    {
                        //IF NOT ALLOW COMBINE, REMOVE ALL EXCEPT THIS COUPON
                        for (int i = (basket.BasketCoupons.Count - 1); i >= 0; i--)
                        {
                            if (basket.BasketCoupons[i] != recentCoupon)
                            {
                                if (previousCouponsRemoved.Length > 0)
                                {
                                    previousCouponsRemoved += "," + basket.BasketCoupons[i].Coupon.Name;
                                }
                                else
                                {
                                    previousCouponsRemoved = basket.BasketCoupons[i].Coupon.Name;
                                }
                                basket.BasketCoupons.DeleteAt(i);
                            }
                        }
                    }

                    basket.Save();
                    basket.Recalculate();
                }
                else
                {
                    //Invalid Coupon
                    //Output couponValidityMessage here
                }
            }
            else
            {
                //"The coupon code you've entered is already in use.<br /><br />";
            }
        }
        else
        {
            //"The coupon code you've entered is invalid.<br /><br />";
        }
    }
This function will help you apply coupon through code

4)- Now locate following code in CheckingOut(object sender, CheckingOutEventArgs e) method

Code: Select all

//to enable scripted load testing, we need to allow recalculation of the basket hash
        if (!string.IsNullOrEmpty(Request.Form["RecalcHash"]))
and make it look like

Code: Select all

string couponCode = string.Empty;
        if (Session["CouponCode"] != null)
        {
            couponCode = Session["CouponCode"].ToString();
            if(!string.IsNullOrEmpty(couponCode))
                ApplyCoupon(couponCode);
        }
//to enable scripted load testing, we need to allow recalculation of the basket hash
        if (!string.IsNullOrEmpty(Request.Form["RecalcHash"]))
this mod will automatically apply any coupon found in session when user tires to checkout.

kbeazer
Ensign (ENS)
Ensign (ENS)
Posts: 15
Joined: Sun Mar 07, 2010 7:44 pm

Re: Coupon for first-time buyers

Post by kbeazer » Tue Mar 09, 2010 1:52 pm

Thanks so much for the info.

I have tried to make this work with the non-onepage checkout and can't seem to get it to work. Step #2 I did, and then for #3 I pasted that code into the PaymentPage.aspx.cs and then for #4 there is no where to replace since that code only exists in the OnePageCheckout.ascx.cs .

So in short, how can I do this when not using the OnePageCheckout?

Thanks so much for your help.
Kevin

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Coupon for first-time buyers

Post by mazhar » Wed Mar 10, 2010 8:14 am

For payment page give a try and locate following code statement

Code: Select all

checkoutResponse = Token.Instance.User.Basket.Checkout(checkoutRequest);
and then put following code block just above it something like

Code: Select all

string couponCode = string.Empty;
        if (Session["CouponCode"] != null)
        {
            couponCode = Session["CouponCode"].ToString();
            if(!string.IsNullOrEmpty(couponCode))
                ApplyCoupon(couponCode);
        }

kbeazer
Ensign (ENS)
Ensign (ENS)
Posts: 15
Joined: Sun Mar 07, 2010 7:44 pm

Re: Coupon for first-time buyers

Post by kbeazer » Fri Apr 16, 2010 9:51 am

I can't seem to get it to work. I have implemented the Global.asax adjustment and since I am not using the one page checkout, I have implemented the code above on the payment.ascx.cs file in the ConLib. The pages load without errors and things after the code is implemented, however, the coupon is not applied.

I am wondering if either the coupon in Global.asax is not being set to string correctly or if the Payment.ascx.cs file is not catching it correctly.

The goal is to pass a coupon a url. Then when the user checks out, the coupon will be applied automatically to their order as if they entered the coupon manually.

Can someone please help? I would really appreciate it. Thanks Mazhar so much for your help on this.

Thanks is Advance.

adam225
Ensign (ENS)
Ensign (ENS)
Posts: 1
Joined: Wed Dec 08, 2010 6:26 am

Re: Coupon for first-time buyers

Post by adam225 » Wed Dec 08, 2010 6:33 am

Thank you so much for these info.

Post Reply