Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default 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

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

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

  2. #2
    Join Date
    Nov 2007
    Location
    Essex, UK
    Posts
    137
    Plugin Contributions
    1

    Default 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

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

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

 

 

Similar Threads

  1. Change State to use ISO Codes
    By kwright in forum General Questions
    Replies: 3
    Last Post: 26 Feb 2009, 06:54 PM
  2. replace ISO codes for country codes
    By froldao in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 1 May 2008, 05:39 PM
  3. State problem with new account (when making state field not required)
    By earmsby in forum Managing Customers and Orders
    Replies: 9
    Last Post: 13 May 2007, 10:04 PM
  4. OOPS! lost usa and state codes
    By ogie56 in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 3
    Last Post: 26 Apr 2007, 10:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •