Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / Need Coupon Zone Restriction by Shipping Address

Need Coupon Zone Restriction by Shipping Address

Views: 2,899

Results 1 to 18 of 18
25 Mar 2011, 6:38 PM
#1
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Need Coupon Zone Restriction by Shipping Address

Hi Newbie Zen Cart user, here. I'm running v1.3.9h and I've run across something I can't untangle.

I've created a coupon that I want only deployed military customers (using APO/FPO addresses) to use. I have restrictions on the categories, and I set up a "military" zone that includes all the "states" (AE, AP, etc.).

It appears to work fine except for the problem that breaks it - that being, of course, that zone restrictions apply to the billing address, which is not the APO address. (In other words, when I use the APO address as the billing, it's applied as expected.)

I know what I'm wanting to do was actually a bug in previous versions. I've looked at some older versions of ot_coupon.php, but the code has changed enough that with my limited php knowledge I can't untangle it. Even if I could, I have no idea if other code needs modification as well.

I don't have any problem changing core code because (at this time), no other coupons would have a need for zone restrictions.

Any code snippets or advice would be most appreciated. I promised soldiers a coupon, but I don't want to post it until I can control who uses it.

Thanks!

25 Mar 2011, 6:44 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

You would need to customize the Order Total module for Discount Coupons ot_coupons and have it use the Delivery Address on your coupons rather than the Billing Address ...

Currently, the restrictions only use the Delivery Address on Free Shipping for the restrictions ...

If you look in the code around line 267 you will see the start of the code for which address is used on the restrictions ...

25 Mar 2011, 7:08 PM
#3
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Fantastic! What a quick response! That's close to where I was at - I was looking around line 309 at the code commented with "...always validate coupon for payment address changes."

Do you know which line is calling for the address? I've got a ways to go before I can read php with any confidence.

Thanks for your help!

25 Mar 2011, 7:10 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

There are two case statements ... one for the country and one for the zone id ...

You need to adjust them for whether they pull Delivery or Billing ...

25 Mar 2011, 7:28 PM
#5
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Odd - I searched TABLE_ZONES_TO_GEO_ZONES in Zen cart admin tools, and, as you stated, it's around line 286, but in opening the php file, it's line 573. I'll have to unravel that one later...

So the following commented out:

// $sql = "select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id";

And is followed by:

  •      $sql = "select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $check_zone_country_id . "' order by zone_id";
    
        $check = $db->Execute($sql);*
    

I'm assuming what I want is:

'" . $check_zone_country_id . "'

Am I in the right direction still?

25 Mar 2011, 7:30 PM
#6
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Sorry - didn't see your last post until after I posted again. OK, thanks, I'll keep at it!

25 Mar 2011, 7:31 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

If you are using the restrictions ... have you look at the two sections labeled:

          // base restrictions zone restrictions for Delivery or Billing address
25 Mar 2011, 7:52 PM
#8
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

:clap: Got it! I'm brain-fried, I kept looking for *$order->shipping * in spite of "delivery" being right there in front of me :blink:

Thanks for your help!

25 Mar 2011, 7:52 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

You are most welcome ... thanks for the update that you were able to alter this to your needs ...

25 Mar 2011, 8:23 PM
#10
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Not a prob! I'm just glad you were there before I gave myself a head wound lol

If zen cart has (and I'm sure it does) a bug/request tracker, maybe this would work as an admin option? Even handier might be the option to set individual coupons. (But more likely, I'm one in a million who would set it this way).

Thanks again!

25 Mar 2011, 8:26 PM
#11
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

That would be an interesting feature based on a per Discount Coupon ...

Glad you have this working for you ... :smile:

29 Sep 2011, 12:09 AM
#12
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Hi Ajeh,
I'm trying to accomplish the exact same thing with a Free Shipping Coupon. I need the coupon code to check the shipping address not the billing. I'm using version 1.3.7.1 I looked through ot_coupon.php and had no luck finding an area to edit. Any ideas what file I need to edit and which area of that file?
Thanks

4 Oct 2011, 11:18 PM
#13
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Anybody? ZenCart version 1.3.7.1 and needing to change the free shipping coupon to check the shipping address at checkout, not the billing address. Thanks.

5 Oct 2011, 12:14 AM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

You might try comparing the file:
/includes/modules/order_total/ot_coupon.php

to the one that comes with the current version of 1.3.9h and see the code differences and how that can be changed ...

6 Oct 2011, 5:21 PM
#15
sjrily avatar

sjrily

New Zenner

Join Date:
Mar 2011
Posts:
14
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

Look for the code Ajeh referenced in post #7

6 Oct 2011, 5:29 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

This is in the code for the current v1.3.9h ... what version are you using? :unsure:

7 Oct 2011, 12:39 AM
#17
jgraphics avatar

jgraphics

New Zenner

Join Date:
Oct 2006
Posts:
75
Plugin Contributions:
0

Re: Need Coupon Zone Restriction by Shipping Address

I'm using version 1.3.7.1

7 Oct 2011, 12:43 AM
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Need Coupon Zone Restriction by Shipping Address

You would need to compare the files from v1.3.9h and v1.3.7 and find the code in v1.3.9h and see if you can adapt that to your v1.3.7 ...