Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Address Book State blank or missing


WhiteKnight

Recommended Posts

Hi all,

 

When entering a new customer, changing an address or adding another address the State Field does not get saved to the database! (No NY or FL or OH etc just an empty field.)

Everything else gets saved OK. Including address info (gender, company, name, street, state, post code and country) and database related info (customers_id, country_id and zone_id).

On screen to the customer it looks OK and shows the 2 letter State (which I think osC gets from the zone_id).

 

It used to work <g>, but ... lots of code changes later... things are not always what they seem.

I don't think I made any changes in any of the code for the customer data or address data. Lots in the language files but only for text display purposes.

There are some changes in the database but I am not sure they would affect this. The Countries, Zones, Geo_Zones and Zones_to_Geo_Zones have had non US data removed. (This site only sells products usable in the US and some US territories.)

67 counties have been added to Zones etc for FL to change sales tax by county. (And that calculates correctly based on the shipping location). All the related ID fields match up (67 in Geo_Zones and zones_to_Geo_Zones. There are 125 records in Zones - 67 from FL, 49 other states and 9 territories).

 

It all looks OK on screen and seems to work OK in testing, except I added Zone Shipping by State and it uses the State info from the shipping address at the time of checkout to get the Zone. This works correctly if the state is in the address_book table (old test records or manually edited) But there is no state info in the database being added now so no shipping (and of course that means no orders will process).

 

I tried using the last known good files, but it is hard to tell when it was good since it all looks good on screen. So what happened to it saving the state data in the address_book table? I've look thru a few hundred posts on here that were loosely related, but did not solve the issue.

 

There is probably something really simple I am missing (inadvertent delete key or extra . somewhere or a // where they should not be. If only my fingers would do what my mind wants them to.

 

TIA,

 

Walter

Link to comment
Share on other sites

OK, so now being a little wiser about how the entry_state is used I see what is wrong.

 

The things I found that seemed relevant, but did not solve the issue for me (but may for someone else who finds this post by searching) included :

 

Making sure State was set to True in admin/Configuration/Customer Details

 

Making sure Country and Zone are correct in admin/Configuration/My Store

 

Making sure Address Format is correct in admin/Locations-Taxes/Countries

(for US based addresses this seems to be 6 and is detailed in the catalog/includes/functions/general.php file and stored in the address_format table)

 

What fixed the issue was changing the way osC gets the state.

 

Addresses are input or modified in 4 files. In the catalog/ create_account.php, address_book_process.php, checkout_payment_address.php and checkout_shipping_address.php.

The code in all of them includes this section:

 

if (ACCOUNT_STATE == 'true') {
  if ($zone_id > 0) {
  $sql_data_array['entry_zone_id'] = (int)$zone_id;
  $sql_data_array['entry_state'] = '';
  } else {
  $sql_data_array['entry_zone_id'] = '0';
  $sql_data_array['entry_state'] = $state;
  }
}

 

So the problems is that if the zone_id is > 0 then entry_state is ' '

But in my case the zone_id is always > 0 (each state has a zone_id) so osC saves ' ' (nothing) in the entry_state field in the address_book table!

It displays the right state on screen by using the zone_id and looking up the state name in another table.

Yes that is a little more normalized, but it does cause issues if you want to use the state name for something else that just gets it based on what is in the entry_state field (like zone shipping by state).

Simply changing the one line

from = ' ';

to = $state;

fixes that issue.

 

Of course it needs to be done in all 4 files noted above.

 

It gives the same result now if the zone_id is > 0 or if it is = 0 so any logic that is dependent on that would not work.

(You could make it a range line > 0 and <52 or whatever you need for your table)

 

You could also simplify the code so there is no if statement that produces the same result as the else statement.

 

You could also make a function in the general.php file that handles this and not have the same code in 4 different files.

That function could handle all the address_table code from the above 4 files, not just the state issue.

But this was a simple way to fix the issue I was having and did not change the original code very much so it is easy to change back or modify in the future.

 

Note this has only been tested with US addresses since that is all this site deals with and using other address formats, not having states, etc may give you very different results.

 

Walter

Link to comment
Share on other sites

Also if you want to store the 2 letter name only as uppercase for string matching use elsewhere just make it

= strtoupper($state);

 

Note that only applies to this mod to save it in the address_book table.

osC will default to show it on screen however it is in the zones table as zone_code (like VA), which starts out as uppercase, or the text version from zone_name (like Virginia).

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...