Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Change State name to State Code


npn2531

Recommended Posts

Posted

Hi

 

Trouble is that the orders table in the db has the customers_state, billing_state and delivery_state as the full name.

 

You could do this stuff http://www.oscommerce.com/forums/topic/345449-zone-code-vs-zone-name/ (bottom post on the page)

 

Or you could do a little bit of code stuff - admin /includes/functions/general.php edit this function:

 

 function tep_address_format($address_format_id, $address, $html, $boln, $eoln) {
   $address_format_query = tep_db_query("select address_format as format from " . TABLE_ADDRESS_FORMAT . " where address_format_id = '" . (int)$address_format_id . "'");
   $address_format = tep_db_fetch_array($address_format_query);
   $company = tep_output_string_protected($address['company']);
   if (isset($address['firstname']) && tep_not_null($address['firstname'])) {
  $firstname = tep_output_string_protected($address['firstname']);
  $lastname = tep_output_string_protected($address['lastname']);
   } elseif (isset($address['name']) && tep_not_null($address['name'])) {
  $firstname = tep_output_string_protected($address['name']);
  $lastname = '';
   } else {
  $firstname = '';
  $lastname = '';
   }
   $street = tep_output_string_protected($address['street_address']);
   $suburb = tep_output_string_protected($address['suburb']);
   $city = tep_output_string_protected($address['city']);
   $state = tep_output_string_protected($address['state']);
   if (isset($address['country_id']) && tep_not_null($address['country_id'])) {//nope
  $country = tep_get_country_name($address['country_id']);
  if (isset($address['zone_id']) && tep_not_null($address['zone_id'])) {
    $state = tep_get_zone_code($address['country_id'], $address['zone_id'], $state);
  }
   } elseif (isset($address['country']) && tep_not_null($address['country'])) {
  $country = tep_output_string_protected($address['country']);
   } else {
  $country = '';
   }


//wee bit for America
if($country=='United States')
{
$state_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_country_id = '223' and zone_name = '" . $state . "' limit 1");
   if (tep_db_num_rows($state_query))
{
  $state_values = tep_db_fetch_array($state_query);
	 $state = $state_values['zone_code'];
   }   
}
//ends

   $postcode = tep_output_string_protected($address['postcode']);
   $zip = $postcode;
   if ($html) {
// HTML Mode
  $HR = '<hr />';
  $hr = '<hr />';
  if ( ($boln == '') && ($eoln == "\n") ) { // Values not specified, use rational defaults
    $CR = '<br />';
    $cr = '<br />';
    $eoln = $cr;
  } else { // Use values supplied
    $CR = $eoln . $boln;
    $cr = $CR;
  }
   } else {
// Text Mode
  $CR = $eoln;
  $cr = $CR;
  $HR = '----------------------------------------';
  $hr = '----------------------------------------';
   }
   $statecomma = '';
   $streets = $street;
   if ($suburb != '') $streets = $street . $cr . $suburb;
   if ($country == '') $country = tep_output_string_protected($address['country']);
   if ($state != '') $statecomma = $state . ', ';
   $fmt = $address_format['format'];
   eval("\$address = \"$fmt\";");
   if ( (ACCOUNT_COMPANY == 'true') && (tep_not_null($company)) ) {
  $address = $company . $cr . $address;
   }
   return $address;
 }

 

Alternative woudl be to edit the catalog function to save the zone_code instead of zone_name during the order process

Posted

Thank you Bob, your 'wee bit for America' works just fine!

 

Now in a perfect world, at least for my business, if the country was 'United States', then the country part of the address, the last line, would be blank. I have spent a wee bit of time hacking around on your nicely modified function tep_address_format but to no avail. Any ideas?

Oscommerce site:

 

 

OSC to CSS, http://addons.oscommerce.com/info/7263 -Mail Manager, http://addons.oscommerce.com/info/8120

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...