Page 1 of 1

Coupon only for customers not in a group

Posted: Thu Jul 09, 2009 4:39 am
by Jaz
I noticed that there are a lot of post about people trying to do complicated things with coupons. I just need to do something simple, but I am stumped.

Most of my customers are not assigned to a group. These are my retail customers and the ones I want my coupons to apply to. I want to make coupons that apply to everyone that is not in a group and exclude everyone that is in a group. This coupon should also work for new customers that have not registered.

I know how to asign a coupon to a group, but how do I exclude all customers that are assigned a group?

Re: Coupon only for customers not in a group

Posted: Thu Jul 09, 2009 6:38 am
by kastnerd
maybe make a group called "no group" and make it so all non users are assigned to this group automatically.

Re: Coupon only for customers not in a group

Posted: Thu Jul 09, 2009 2:49 pm
by Jaz
Is there a way to automatically asign a group? Would it work for those who choose not to make an account? Is there a way to quickly asign all my old customers to this group?

Re: Coupon only for customers not in a group

Posted: Fri Jul 10, 2009 6:25 am
by mazhar
You can try something like below to automatically add customers to some user group. For example below code will put customers into a group with group id 11

Code: Select all

foreach (User user in Token.Instance.Store.Users)
        {
            if (!user.IsInGroup(11))
            {
                UserGroup userGroup = new UserGroup(user.UserId, 11);
                user.UserGroups.Add(userGroup);
                user.User.Save();
            }
        }

Re: Coupon only for customers not in a group

Posted: Fri Jul 10, 2009 1:35 pm
by Jaz
Thanks! Now, where would I put this code? Will this do anything to help me reasign all the existing customers?

Re: Coupon only for customers not in a group

Posted: Sat Jul 11, 2009 3:18 am
by mazhar
Please read following post. You can place some button one some suitable page to carry this out
viewtopic.php?f=42&t=9207

Re: Coupon only for customers not in a group

Posted: Sat Jul 11, 2009 3:34 pm
by Jaz
Just one more question. Does the script only put unassigned users in a group, or will it affect users that are already assigned to a group?

Re: Coupon only for customers not in a group

Posted: Sun Jul 12, 2009 10:21 am
by Logan Rhodehamel
Another approach that might be simpler would be to make a custom change to the control that accepts a coupon code from the customer. You could create your coupon and not apply a group filter. Then in the coupon code control, add a little bit of code something like:

Code: Select all

if (couponcode == "mycode" && user is not in a group)
And wrap that around the line that applies the coupon. Then you won't have to do anything with automated group memberships.

Re: Coupon only for customers not in a group

Posted: Sun Jul 12, 2009 4:26 pm
by wave_werks
Logan_AbleCommerce wrote:Another approach that might be simpler would be to make a custom change to the control that accepts a coupon code from the customer. You could create your coupon and not apply a group filter. Then in the coupon code control, add a little bit of code something like:

Code: Select all

if (couponcode == "mycode" && user is not in a group)
And wrap that around the line that applies the coupon. Then you won't have to do anything with automated group memberships.
If anyone tries this method with success please, please, please post back with the code used to make it work and any comments on your experience in getting it to work. We have been looking for a way to give out coupon codes to everyone - which includes advertising in print/web/etc to prospective customers who would not yet be in a group. This would be a HUGE deal for us if it works.

@Logan: I'm not an expert code writer so a lot of this stuff is very foreign to me. How would I "wrap that around the line that applies the coupon"?

Thanks!

Re: Coupon only for customers not in a group

Posted: Tue Jul 14, 2009 9:05 am
by Logan Rhodehamel
In the files ConLib/CouponDialog.ascx.cs and ConLib/PaymentPage.ascx.cs, there is code that looks something like this:

Code: Select all

        if (coupon != null)
        {
            if (!CouponCalculator.IsCouponAlreadyUsed(Token.Instance.User.Basket, coupon))
            {
This is the area that is best suited to implement exclusions for coupons that should only apply to users without any group assignment. The code would be changed to something like this:

Code: Select all

        if (coupon != null)
        {
            // THIS IS A LIST OF COUPON CODES THAT SHOULD ONLY APPLY TO USERS WITHOUT GROUP ASSIGNMENT
            // ENTER THE CODES IN ALL UPPER CASE
            string[] noGroupCoupons = { "NOGROUP1", "NOGROUP2" };
            // THIS CODE CHECKS IF THE COUPON REQUESTED IS IN THE NO GROUP LIST
            bool couponAppliesToNoGroup = (Array.IndexOf(noGroupCoupons, coupon.CouponCode.ToUpperInvariant()) > -1);
            // A COUPON PASSES GROUP CHECK IF IT IS NOT IN THE NO GROUP LIST, OR THE USER HAS NO GROUPS
            bool passesGroupCheck = (!couponAppliesToNoGroup || Token.Instance.User.UserGroups.Count == 0);
            if (!CouponCalculator.IsCouponAlreadyUsed(Token.Instance.User.Basket, coupon) && passesGroupCheck)
            {
With this modification, you just provide a list of coupon codes that should only apply to users without a group. Make sure to enter them in all upper case characters.

Then, further down the code (maybe 50 lines down) will be code like this:

Code: Select all

                InvalidCouponMessage.Text = "The coupon code you've entered is already in use.";
The code is slightly different between the two files but this is where the message is being set for an invalid coupon. You will probably want to show a message particular to the situation where a coupon code is not valid because of the group exclusion:

Code: Select all

                if (!passesGroupCheck) InvalidCouponMessage.Text = "The coupon code is only available to retail customers.";
                else InvalidCouponMessage.Text = "The coupon code you've entered is already in use.";

Re: Coupon only for customers not in a group

Posted: Tue Jun 07, 2011 4:18 pm
by hassonmike
Logan, I tried the code you suggested, but is still accepting coupons from users in groups. I see that this post is kind of old, might there be some changes needed to bring this up to date?

Re: Coupon only for customers not in a group

Posted: Wed Apr 03, 2013 2:58 pm
by illyrianmoon
Has anyone successfully added this? I, too, added the code, but it didn't seem to make a difference. Our dealers are combining volume discounts with a coupon, and if I specify which groups can use the coupon, regular customers can't use the coupon. :|