Coupon only for customers not in a group

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
Jaz
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Nov 05, 2008 4:04 am
Location: Torrance, CA
Contact:

Coupon only for customers not in a group

Post by Jaz » Thu Jul 09, 2009 4:39 am

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?
David Jasiewicz
President
Trick Concepts - Metal Fab. Engineering and Product Design
http://www.trickconcepts.com-- If you are an ASP or PHP programmer or CSS web specialist I will gladly trade for graphic design, mechanical engineering or metal fabrication service! --

kastnerd
Commodore (COMO)
Commodore (COMO)
Posts: 474
Joined: Wed Oct 22, 2008 9:17 am

Re: Coupon only for customers not in a group

Post by kastnerd » Thu Jul 09, 2009 6:38 am

maybe make a group called "no group" and make it so all non users are assigned to this group automatically.

User avatar
Jaz
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Nov 05, 2008 4:04 am
Location: Torrance, CA
Contact:

Re: Coupon only for customers not in a group

Post by Jaz » Thu Jul 09, 2009 2:49 pm

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?
David Jasiewicz
President
Trick Concepts - Metal Fab. Engineering and Product Design
http://www.trickconcepts.com-- If you are an ASP or PHP programmer or CSS web specialist I will gladly trade for graphic design, mechanical engineering or metal fabrication service! --

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

Re: Coupon only for customers not in a group

Post by mazhar » Fri Jul 10, 2009 6:25 am

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();
            }
        }

User avatar
Jaz
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Nov 05, 2008 4:04 am
Location: Torrance, CA
Contact:

Re: Coupon only for customers not in a group

Post by Jaz » Fri Jul 10, 2009 1:35 pm

Thanks! Now, where would I put this code? Will this do anything to help me reasign all the existing customers?
David Jasiewicz
President
Trick Concepts - Metal Fab. Engineering and Product Design
http://www.trickconcepts.com-- If you are an ASP or PHP programmer or CSS web specialist I will gladly trade for graphic design, mechanical engineering or metal fabrication service! --

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

Re: Coupon only for customers not in a group

Post by mazhar » Sat Jul 11, 2009 3:18 am

Please read following post. You can place some button one some suitable page to carry this out
viewtopic.php?f=42&t=9207

User avatar
Jaz
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Nov 05, 2008 4:04 am
Location: Torrance, CA
Contact:

Re: Coupon only for customers not in a group

Post by Jaz » Sat Jul 11, 2009 3:34 pm

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?
David Jasiewicz
President
Trick Concepts - Metal Fab. Engineering and Product Design
http://www.trickconcepts.com-- If you are an ASP or PHP programmer or CSS web specialist I will gladly trade for graphic design, mechanical engineering or metal fabrication service! --

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: Coupon only for customers not in a group

Post by Logan Rhodehamel » Sun Jul 12, 2009 10:21 am

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.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

wave_werks
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 91
Joined: Mon Sep 22, 2008 8:37 pm
Location: Northeast Ohio
Contact:

Re: Coupon only for customers not in a group

Post by wave_werks » Sun Jul 12, 2009 4:26 pm

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!
- Jeff
Wave Werks

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: Coupon only for customers not in a group

Post by Logan Rhodehamel » Tue Jul 14, 2009 9:05 am

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.";
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

User avatar
hassonmike
Lieutenant (LT)
Lieutenant (LT)
Posts: 76
Joined: Tue Apr 19, 2011 2:13 pm
Contact:

Re: Coupon only for customers not in a group

Post by hassonmike » Tue Jun 07, 2011 4:18 pm

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?

illyrianmoon
Ensign (ENS)
Ensign (ENS)
Posts: 17
Joined: Thu Apr 07, 2011 4:31 pm

Re: Coupon only for customers not in a group

Post by illyrianmoon » Wed Apr 03, 2013 2:58 pm

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. :|

Post Reply