Turn Off Case Sensitivity for Coupon Code

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 anos atrás
Anyone know how to turn off the case sensitive requirement for coupon codes?
13 anos atrás
You need to modify NopSolutions.NopCommerce.BusinessLogic.Promo.Discounts.Discount.IsActive(string couponCodeToValidate) method. Replace
if (couponCodeToValidate != this.CouponCode)

with
if (couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
13 anos atrás
Maybe I'm doing this wrong, but I can't get that to work.

I made the change, then I Rebuild the entire solution, then I Published nopCommerceStore. That should propagate the change shouldn't it?

This is what the change looks like:


            if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
            {
                if (couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
                    return false;
            }
13 anos atrás
change tothis

       if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
            {
                if (!couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
                    return false;
            }

or this

       if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
            {
                if (couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
                    return true;
            }
13 anos atrás
I figured out another work-around:

In modules>OrderSummary.ascx.cs, at line 254 it grabs the coupon code with,


            string couponCode = this.txtDiscountCouponCode.Text.Trim();

I added on the following line

            couponCode = couponCode.ToLower();

that forces the code to all lower case. Now i just make sure that I enter only lower case when I set the codes up, and it will not matter how the user enters it, it will match.

A bit of a hack, but it works.

Thanks for all the suggestions.
13 anos atrás
rev23dev wrote:
change tothis

if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
    {
        if (!couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
            return false;
    }

or this

if (this.RequiresCouponCode && !String.IsNullOrEmpty(this.CouponCode))
    {
        if (couponCodeToValidate.Equals(this.CouponCode, StringComparison.InvariantCultureIgnoreCase))
            return true;
    }


You don't want to use the second suggested change (return true after the comparison) as this would skip the other validations ("deleted" check and "start/end date" check) for the coupon code later in the method. The first change (adding !) is needed though.

.
13 anos atrás
[email protected] wrote:
I figured out another work-around:

In modules>OrderSummary.ascx.cs, at line 254 it grabs the coupon code with,


            string couponCode = this.txtDiscountCouponCode.Text.Trim();

I added on the following line

            couponCode = couponCode.ToLower();



I'm using this workaround for my solution. Can one of these solutions be added to the next build? I can't see a reason why the coupon code would ever need to be case sensitive.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.