Jump to content
stevel

Country-State Selector

Recommended Posts

hi,

first of all.. it's a great contribution.. Great Job, Stevel.

 

I'm going to sell within the US only..

 

How can I eliminate all other countires..

 

I think I saw some codes such as

DROP TABLE IF EXISTS countries;
CREATE TABLE countries (
countries_id int NOT NULL auto_increment,
countries_name varchar(64) NOT NULL,
countries_iso_code_2 char(2) NOT NULL,
countries_iso_code_3 char(3) NOT NULL,
address_format_id int NOT NULL,
PRIMARY KEY (countries_id),
KEY IDX_COUNTRIES_NAME (countries_name)
);

 

but, I don't know where I should put..on myphpadmin

 

Can you help me on this?

 

Thanks

Share this post


Link to post
Share on other sites

I just added these codes in countries table at myphpadmin.

 

But doesn't work... I can't even choose any country..

 

gotto be changed somewhere..

Share this post


Link to post
Share on other sites

I just figured it out..

 

I missed a code ..

 

It should be like this.

 

On your myphpadmin page,

click on SQL query and paste this in the box and click go

DROP TABLE IF EXISTS countries;
CREATE TABLE countries (
countries_id int NOT NULL auto_increment,
countries_name varchar(64) NOT NULL,
countries_iso_code_2 char(2) NOT NULL,
countries_iso_code_3 char(3) NOT NULL,
address_format_id int NOT NULL,
PRIMARY KEY (countries_id),
KEY IDX_COUNTRIES_NAME (countries_name)
);

INSERT INTO countries VALUES (223,'United States','US','USA', '2');

 

 

 

A good thing to know..

 

hope it will help someone..

Share this post


Link to post
Share on other sites

I change this in

address_book_details.php

and in

create_account.php

from

///////////

if (count($zones_array) > 0) {

echo tep_draw_pull_down_menu('zone_id', $zones_array, $entry['entry_zone_id']);

echo tep_draw_hidden_field('state', '');

//////////

 

to

//////////

if (count($zones_array) > 0) {

$zones_array[] = array('id' => '', 'text' => '-- '.PULL_DOWN_DEFAULT .' --');

echo tep_draw_pull_down_menu('zone_id', $zones_array, $entry['entry_zone_id']);

echo tep_draw_hidden_field('state', '');

//////////

 

if you have a country with a zone the list start with your language PULL_DOWN_DEFAULT

 

ciao

Mario

 

;)

Share this post


Link to post
Share on other sites

Hi

 

This is a fantastic contribution, however I am having problems with the refresh.

 

Basically when I change the country when signing up for an account I get an error as follows:

 

Line: 280, Char: 1, Error: Object expected, Code: 0, Url: /catalog/create_account.php etc...

 

Then I tested it with an already setup account, I went to change the county and I got the following error:

 

Line: 369, Char:1, Error: Object expected, Code: 0,

Url: /catalog/address_book_process.php etc...

 

I would apreciate anybodys help with the above..

 

Thanks

Share this post


Link to post
Share on other sites

Do you have a URL I can look at? Feel free to send it to me in a PM if you want.

 

Or, if you want to try to diagnose it yourself - bring up the create_account page in the browser. Select Edit..View Source (or whatever the command is is your browser). Save the source as a file on your computer. In a text editor that does line numbers, see what line 280 is. It will be somewhere in the JavaScript of form_check_js.php. Whatever value is being referenced on that line doesn't exist in the form.

Share this post


Link to post
Share on other sites

Excellent contribution. I've got it set up and working well... but now I'm trying to add in-state sales tax to my (Vermont-based) site, and getting some trouble. I've posted about that here: http://forums.oscommerce.com/index.php?act=ST&f=1&t=95981

 

Could this contribution be messing with the tax zones in some way? Or am I just looking for excuses for my own foolish mistakes?

 

I'm working on this as we speak, hopefully I'll find the problem soon but thanks for any pointers in the meantime...

 

Michael

Share this post


Link to post
Share on other sites

Hi, I just installed this great contribution but I am having one problem. I think it has to do with another contribution that I have (D.O.B. Drop downs). Basically when you choose another country and the page refreshes, I get an error message that looks like this:

 

My Account Information

 

 

 

NOTE: If you already have an account with us, please login at the login page.

 

Your Personal Details * Required information

 

Gender: Male Female *

First Name: *

Last Name: *

Date of Birth:

Fatal error: [] operator not supported for strings in /home/crisil-s/public_html/ecommerce/os/catalog/create_account.php on line 370

 

Here is my code: for that line:

if (ACCOUNT_DOB == 'true') {

?>

<tr>

<td class="main"><?php echo ENTRY_DATE_OF_BIRTH; ?></td>

<!-- <td class="main"><?php echo tep_draw_input_field('dob') . ' ' . (tep_not_null(ENTRY_DATE_OF_BIRTH_TEXT) ? '<span class="inputRequirement">' . ENTRY_DATE_OF_BIRTH_TEXT . '</span>': ''); ?></td> -->

<td class="main">

<?php

// 1. first line

 

for ($i=1; $i<32; $i++) {

$dob_day[] = array('id' => sprintf('%02d', $i), 'text' => sprintf('%02d', $i));

}

 

for ($i=1; $i<13; $i++) {

$dob_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));

}

 

$today = getdate();

$first_year = $today['year'] - 77;

$last_year = $today['year'] - 17;

for ($i=$first_year; $i < $last_year; $i++) {

$dob_year[] = array('id' => sprintf('%02d', $i), 'text' => sprintf('%02d', $i));

}

 

 

echo tep_draw_pull_down_menu('dob_day', $dob_day);

echo tep_draw_pull_down_menu('dob_month', $dob_month);

echo tep_draw_pull_down_menu('dob_year', $dob_year);

 

// last line

?>

</td><?php

}

?>

<tr>

 

 

 

 

Any help would be appreciated!


Mark

 

Contributions Used:

STS

B2B Suite

Description in Product Listing

Header Tag Controller

Easypopulate

Purchase Orders

USA Flag

Local Delivery

New Attributes Editor

Pickup

Share this post


Link to post
Share on other sites

Dear Steve Lionel

 

Please do us a favor and post your Paypal information. If not in the install instructions than at least here... The cleanest install ever! I could basically search and replace with dreamweaver!

 

And now a question / comment to the last post:

 

Hi, I just installed this great contribution but I am having one problem. I think it has to do with another contribution that I have (D.O.B. Drop downs). Basically when you choose another country and the page refreshes, I get an error message that looks like this:

 

My Account Information

 

 

 

NOTE: If you already have an account with us, please login at the login page.

 

Your Personal Details * Required information

 

Gender: Male Female *

First Name: *

Last Name: *

Date of Birth:

Fatal error: [] operator not supported for strings in /home/crisil-s/public_html/ecommerce/os/catalog/create_account.php on line 370

 

Nice you ever got the DOB Contrib to work. Did you change the create_account.php so it did not check on dob, if someone accidently did not fill in properly? That always gave me an error! But, I agree it be nice in combination with the country-state-selector.

Edited by SwissChris

Share this post


Link to post
Share on other sites

The DOB contribution works great by itself, but not with the country-state selector. I removed the DOB contribution for now and all is working fine but I would eventually like to get DOB to work again. Back to the drawing board!


Mark

 

Contributions Used:

STS

B2B Suite

Description in Product Listing

Header Tag Controller

Easypopulate

Purchase Orders

USA Flag

Local Delivery

New Attributes Editor

Pickup

Share this post


Link to post
Share on other sites

Stevel,

 

I have encountered the same tax_zone issue (as Spoot mentioned) and I found the actions that are causing it.

 

In table "address_book" there is a field called "entry_zone_id" which is used for cross-referecing the customer with tax zones.

 

When a new account is created, the "entry_zone_id" field is populated correctly and the "entry_state" field is left unpopulated as designed.

 

However, when you change your account details, this field "entry_zone_id" is cleared to "0" and the field "entry_state" is set to your STATE value.

 

Since your changing your account details, one can assume the problem lies within "address_book_process.php", but investigation is required.

 

 

I tested the same actions on the oroginal 2.2ms2 install and what should happen is the "entry_zone_id" field gets updated if the state changes with no updates to "entry_state". If the state entered is not recognized, then "entry_zone_id" gets set to "0" <zero> and the state name is entered into "entry_state".

 

 

I'm not the author of this contrib, but I will look to solve this problem unless someone else does in the mean time....

Share this post


Link to post
Share on other sites

This is the replaced code I found causing the problem:

===================================

<from 1.0.5 install notes>

 

Line 100

 

Replace:

 

$zone_id = 0;

$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");

$check = tep_db_fetch_array($check_query);

$entry_state_has_zones = ($check['total'] > 0);

if ($entry_state_has_zones == true) {

$zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name like '" . tep_db_input($state) . "%' or zone_code like '%" . tep_db_input($state) . "%')");

if (tep_db_num_rows($zone_query) == 1) {

$zone = tep_db_fetch_array($zone_query);

$zone_id = $zone['zone_id'];

} else {

$error = true; $messageStack->add('addressbook', ENTRY_STATE_ERROR_SELECT);

}

} else {

 

with:

 

// +Country-State Selector

if ($zone_id == 0) {

// -Country-State Selector

 

 

 

Here is the updated code that works so far, could use more testing:

===========================================

$zone_id = 0;

$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "'");

$check = tep_db_fetch_array($check_query);

$entry_state_has_zones = ($check['total'] > 0);

if ($entry_state_has_zones == true) {

$zone_query = tep_db_query("select distinct zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' and (zone_name like '" . tep_db_input($state) . "%' or zone_code like '%" . tep_db_input($state) . "%')");

if (tep_db_num_rows($zone_query) == 1) {

$zone = tep_db_fetch_array($zone_query);

$zone_id = $zone['zone_id'];

} else {

$error = true; $messageStack->add('addressbook', ENTRY_STATE_ERROR_SELECT);

}

}

 

// +Country-State Selector

if ($zone_id == 0) {

// -Country-State Selector

 

 

=======================================

basically, we need the functionality to determine the zone_id.

 

so just replace

 

else {

 

with:

 

// +Country-State Selector

if ($zone_id == 0) {

// -Country-State Selector

Share this post


Link to post
Share on other sites

Hi folks..

 

I'm travelling this week and can't help with investigating problems. I'll take a look at these when I return.

 

If you would like to make a donation in support of this contribution, please feel free to donate to the Kitty Angels no-kill cat shelter. Use this link to make a donation using a credit card. Thanks.

Edited by stevel

Share this post


Link to post
Share on other sites

Steve,

 

I installed your contribution on our site and ran into a problem.

 

As far as fixing the problem with the state being reset after an error, the code worked fine. What I saw, was that after the new customer created a new customer record and went on to order something, the order record and the invoice did not contain the customers name and address. Further, in the admin section under customers, the admin could not edit or delete the customer record. The following warning was given.

 

Warning: Variable passed to reset() is not an array or object in /home/www/tackroominc.com/test/admin/includes/classes/object_info.php on line 17

 

Warning: Variable passed to each() is not an array or object in /home/www/tackroominc.com/test/admin/includes/classes/object_info.php on line 18

 

 

we looked at an old customer record (pre contribution) and compaired it to the newly created customer record and determined that the field for the number of addresses was set to 0 in the newly created customer record.

 

In the file, create_account.php I changed the following code,

 

/*

tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . (int)$address_id . "' where customers_id = '" . (int)$customer_id . "'");

*/

tep_db_query("update " . TABLE_CUSTOMERS . " set customers_default_address_id = '" . 1 . "' where customers_id = '" . (int)$customer_id . "'");

 

 

This seems to allow the name and address to be retrieved from the database. Is this enough to corect the problem? Or is there other code that needs changed in other places.

 

Thank You,

Eva

Share this post


Link to post
Share on other sites

Eva, something seems definitely wrong there. I haven't seen that behavior in my own store.

 

$address_id is created in the preceding line by a call to tep_db_insert_id(). I can't imagine what could cause that to fail. Furrthermore, the contribution doesn't change the code in this area.

 

How about you send me a PM with the contents of your create_account.php so I can compare it to mine. Perhaps that will tell me something.

Share this post


Link to post
Share on other sites

calman, I'll admit I didn't think too much about the case where states have zones. Let me play with that and see what I come up with. The idea is that if you have specific zones defined, the zone id should get filled in from the dropdown list and it should not be necessary to do a table lookup. I guess I don't understand the use of state tax zones enough yet - my own state has no tax!

 

Give me an example of how I should set things up to test this.

Share this post


Link to post
Share on other sites

Well, nobody has stepped up to suggest how I should test tax zones, so I stumbled through it myself. The documentation is none too clear on this. But I have a guess as to what is going on.

 

The model of Country-State Selector is that there is a defined Zone for any zone you have an interest in. When the customer selects the country, they are shown ALL the zones for that country, which, if there were multiple tax zones for a state, for instance, there would be a distinct zone for each.

 

Here's what I tried. New Hampshire, where I live, doesn't have sales taxes, so I pretended that two counties, Hillsborough and Rockingham did. First thing is I went to the Zones table and added two new zones, "New Hampshire - Hillsborough" and "New Hampshire - Rockingham". I renamed the existing New Hampshire to "New Hampshire - Other".

 

Next I went to Tax Zones and created two zones, "NH Hills" and "NH Rock". For each, I clicked Details and inserted the specific zone I created above.

 

Last, I went to Tax Rates and created two new rates, one for each of the Tax Zones.

 

When customers create an account or use the address book, and they select United States, they are presented with three New Hampshire zones - they have to pick one of them. I verified that this information is carried over into the order in admin.

 

With Country-State Selector, you don't have the two-step dance of entering the state name and then being prompted to select the specific zone. I suppose it's possible to do that, but it seems rather pointless to me, unless perhaps you have lots of zones with multiple tax rates.

 

If I am misunderstanding the problem, please enlighten me. I want to help.

Share this post


Link to post
Share on other sites

Talking to myself here, perhaps...

 

calman, I tried some experiments and could not reproduce the problem you describe. Perhaps my above explanation of how C-S Selector works is helpful?

Share this post


Link to post
Share on other sites

Love the contrib. This may sound tedious but is there any way for to fix this problem with it, or maybe be fixed in a later release:

 

You go to create account, you have Unites States/Alabama already selected.

If you pick for instance Canada it automatically makes the Province Alberta,

but if you pick for instance...France that has no state/province, it leaves Alabama in but turns it into a text box. Is there anyway to have this deleted like the password field?

 

Thanks,

 

KennethS


Kenneth S

--------------

Customer "Are you a real programmer?"

Me "No, but I did stay at a Holiday Inn Express last night"

Share this post


Link to post
Share on other sites

Well, I took your advice and doublechecked "form_check.js.php" for the statement that is supposed to remove it but it was there. Everything else works perfectly and if that function refreshes the page correctly after changing the country, I would think the rest would work?


Kenneth S

--------------

Customer "Are you a real programmer?"

Me "No, but I did stay at a Holiday Inn Express last night"

Share this post


Link to post
Share on other sites

I believe i've found the solution to that problem you're having. It has to do with the javascript refresh page function. When the country selected already has states, and you attempt to switch to a country that has no states, the javascript function tries to clear a text field, but it should be emptying a combo box instead. I've changed the function in form_check.js.php so it looks like the following:

 

<?php // +Country-State Selector ?>
function refresh_form(form_name) {
  form_name.action.value = 'refresh';

  if (form_name.state.type == 'text')
  {
    form_name.state.value = '';
  }
  else
  {
    for (var i=form_name.state.options.length-1; i>=0; i--)
    {
       form_name.state.options[i] = null;
    }
    form_name.state.selectedIndex = -1;
  }

  form_name.submit();
  return true;
  }
<?php // -Country-State Selector ?>

 

This code assumes that if the type of the state field is text (a country with no list of states), it will clear it normally, but otherwise, it will assume the state field is a combo box and remove the options from the combo box. This has cleared the bug for me... Hope this helps out...

Edited by aqualynx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×