Forums / Built-in Shipping and Payment Modules / Help with state codes

Help with state codes

Locked

Started by nixak on 5 Feb 2010, 2:12 PM · Views: 842

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
5 Feb 2010, 2:12 PM
#1
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Help with state codes

Hi , I need to update my payment script so as if any americans order the customers address details include the state code.

I have written this

if ($order->delivery['country']['iso_code_2'] == 'US') {
		$plain .= "DeliveryState=" . $order->delivery['state'] . "&";
	}else{
		$plain .= "DeliveryState=" . "" . "&";
	}

which sends the state detail only when the customer is from the US, however the field

$order->delivery['state']

sends the state name in full i.e. Alabama and I need to sent just the 2 digit state code.

I have tried lots of different things but unfortunatly I can not seem to get the state code, yet I know (because i've checked) that the database does include these codes.

Any help would be much appriciated.

6 Feb 2010, 6:46 PM
#2
nixak avatar

nixak

Zen Follower

Join Date:
Nov 2007
Location:
Essex, UK
Posts:
137
Plugin Contributions:
1

Re: Help with state codes

Ok a little update, after loads of reading and comparing zen cart files I have found that it should be done more like this

	
  function get_zone_code($order, $default_zone, $zone) {
    global $db;
	$orderstate = $order->billing['state'];
    $zone_query = "select zone_code
                   from " . TABLE_ZONES . "
                   where zone_name = '" . (string)$orderstate . "'";

    $zone = $db->Execute($zone_query);
	
	if ($zone->RecordCount() > 0) {
      return $zone->fields['zone_code'];
    } else {
      return $default_zone;
    }
  }

and later on in the file is this

if (($order->billing['country']['iso_code_2']) == 'US') {
		$plain .= "BillingState=" . $zone->fields['zone_code'] . "&";
	 }else{
		$plain .= "BillingState=" . "&";
    }

I have double checked that my test customer's state is Alaska and everthing up to a point works ..... however when using sagepay's simulater the encryted string shows that the billing state is sent but only as a "&" which I belive is from the else statement in the second block of the code.

Can someone please check this coding and let me know where I have gone wrong. I am using a vanilla 1.3.8a install of zen-cart to test the module