Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Country-State Selector


stevel

Recommended Posts

Nice mod. Several errors in docs - which you can figure out if you look at the source code:

 

address_book_process:

 

the line 13 change should have: ajax_get_zones_html(tep_db_prepare_input($HTTP_POST_VARS['country']), '', true);

(note second blank param, else get '1' for state in zones with no defined states)

 

checkout_payment_address:

 

the line 13 change should have: ajax_get_zones_html(tep_db_prepare_input($HTTP_POST_VARS['country']), '', true);

(note second blank param, else get '1' for state in zones with no defined states)

 

the line 93 change Replace code should include at start: if (ACCOUNT_STATE == 'true') {

 

checkout_shipping_address: sames changes as checkout_payment_address

 

create_account: sames changes as checkout_payment_address

 

customers.php (note the post 'fix' in contrib page is WRONG!):

 

line 196 Replace code should include closing: }

 

Thanks!

Link to comment
Share on other sites

Hey everyone, Id like to apologize for not providing support on the 1.5x versions.. They were modified by me but I just havent had time for the last few months to come in here help with with any problems.. A big thanks to Steve for helping as much as he does with your problems even though he doesnt use the version himself. If there are any big problems you can email me at webmaster AT insaini DOT com.

 

Also for a bit of info..

 

The AJAX Functions file (catalog/includes/functions/ajax.php) has a function

 

function ajax_get_zones_html($country, $default_zone = '', $ajax_output = true) {

 

where $country is a country id, $default_zone is the zone id or state (string) .. and ajax_output either echo's the output directly or does a return

 

the defaults should be noted..

 

at the top of for instance the create_account.php file

 

you only need this

 

  require(DIR_WS_FUNCTIONS . 'ajax.php');

if (isset($_POST['action']) && $_POST['action'] == 'getStates' && isset($_POST['country'])) {
ajax_get_zones_html(tep_db_prepare_input($_POST['country']));
} else {

 

some of you may have

 

 require(DIR_WS_FUNCTIONS . 'ajax.php');

if (isset($_POST['action']) && $_POST['action'] == 'getStates' && isset($_POST['country'])) {
ajax_get_zones_html(tep_db_prepare_input($_POST['country']), '');
} else {

 

or

 

  require(DIR_WS_FUNCTIONS . 'ajax.php');

if (isset($_POST['action']) && $_POST['action'] == 'getStates' && isset($_POST['country'])) {
ajax_get_zones_html(tep_db_prepare_input($_POST['country']), true);
} else {

 

the latter will cause the '1' to show up.. (as true really represents a 1) .. so the default_zone is usually 1 .. best to remove both the extra parameters.. they are only needed on the first call (when the page loads) and have default values

 

so you all should change the code to look like

 

  require(DIR_WS_FUNCTIONS . 'ajax.php');

if (isset($_POST['action']) && $_POST['action'] == 'getStates' && isset($_POST['country'])) {
ajax_get_zones_html(tep_db_prepare_input($_POST['country']));
} else {

 

at the top of those files which require it.. i believe (create_account.php, address_book_process.php, etc..)

 

ALSO

 

if you look below the code shows the 'echo ajax_get_zones_html(....)' ajax function call.. here you can specifiy the default zone you want to show up (false for ajax output is necessary as we are not returning the output and not echoing directly) ..

 

further down you will see how the country selector calls the javascript getStates method..

 

Your code should look like this.. if it doesnt.. you might be having problems.. overall the script works as it should.. however there is the one situation I think someone described.. that they want a list of the most common nations at the top .. this isnt in code.. best to see the ajax function and rework it as you need to..

 

  if (ACCOUNT_STATE == 'true') {
?>
				<tr>
				  <td class="main" width="25%"><?php echo ENTRY_STATE; ?></td>
				  <td class="main"><div id="states">
					  <?php
			// +Country-State Selector
			echo ajax_get_zones_html($country,'',false);
			// -Country-State Selector
			?>
					</div></td>
				</tr>
				<?php
 }
?>
				<tr>
				  <td class="main" width="25%"><?php echo ENTRY_COUNTRY; ?></td>
				  <?php // +Country-State Selector ?>
				  <td class="main" colspan="3"><?php echo tep_get_country_list('country',$country,'class="formtextinput" onChange="getStates(this.value, \'states\');"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>
				  <?php // -Country-State Selector ?>
				</tr>

Edited by insaini
Link to comment
Share on other sites

I have the AJAX 1.5 version of this fantastic contribution working on my site and I appreciate all the hard work you guys have put in.

 

I am having trouble with users registering from the wrong state and tax not being properly charged. For example if someone form California doesn't change the default state (Wyoming for some reason) they don't get charged tax properly.

 

Is there a way to have the select state box default to "please select" instead of one of the zones in the country selected.

 

I found the code for "please select" in the country dropdown box but I just can't figure out where to put it to change the state dropdown to default to "please select".

 

Thanks again guys and great work.

Link to comment
Share on other sites

Here is how I do it - note that I am not using the Ajax version so your edits may be different. Really, it's just the first couple of lines.

 

 // +Country-State Selector
$zones_array = array();
$zones_array[] = array('id' => 0, 'text' => 'Please select...');
$zones_query = tep_db_query("select zone_id, zone_name, zone_code from " . TABLE_ZONES . " where zone_country_id = " . 
  (int)$country . " order by zone_name");
while ($zones_values = tep_db_fetch_array($zones_query)) {
  $zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name'] . ' (' . $zones_values['zone_code'] . ')');
  }
if (count($zones_array) > 1) {
  echo tep_draw_pull_down_menu('zone_id', $zones_array, $zone_id);
} else {
  echo tep_draw_input_field('state');
}
// -Country-State Selector

Link to comment
Share on other sites

I found this code in ajax.php and made the changes but it doesn't do anything to my state selector box.

 

I really need a solution as I expect others may since users can register without properly choosing their state and then not get charged tax properly (i.e California). What a pain.

 

This must be pretty simple to fix since the country box already displays "please select as default.

 

Maybe Jesse will read this and give me an idea.

 

Thanks for the suggestion and all your other help too Steve.

Link to comment
Share on other sites

I found this code in ajax.php and made the changes but it doesn't do anything to my state selector box.

 

I really need a solution as I expect others may since users can register without properly choosing their state and then not get charged tax properly (i.e California). What a pain.

 

This must be pretty simple to fix since the country box already displays "please select as default.

 

Maybe Jesse will read this and give me an idea.

 

Thanks for the suggestion and all your other help too Steve.

 

 

Stevel's code will work for the ajax version except for a minor change..

 

		$zones_array = array();	
			$zones_array[] = array('id' => '', 'text' => 'Please select...');
	$zones_query = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");

 

if you dont see the difference.. the ..'array('id' => '',...);' stevel has a 0 for his code.. but for the ajax version should be an empty string ''

 

i havent tried this but that should work.. its a one line addition to the functions/ajax.php file ..

 

J

Link to comment
Share on other sites

  • 2 months later...

I'm hoping someone can help point me in the right direction.

 

I just installed FEC v2.0, just using the part that combines the checkout_shipping.php and checkout_payment.php pages.

 

I had - Country-State Selector v1.4.1 installed with this added edit:

Single-Country Modification

Modify catalog/create_account.php, catalog/includes/modules/address_book_details.php and catalog/includes/modules/checkout_new_address.php.

Replace this code:

<tr>

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

<?php // +Country-State Selector ?>

<td class="main"><?php echo tep_get_country_list('country',$country,'onChange="return refresh_form(create_account);"') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

<?php // -Country-State Selector ?>

</tr>

with this:

<?php echo tep_draw_hidden_field('country',DEFAULT_COUNTRY); ?>

 

The problem I've come across so far -

 

Here's my steps:

I login or create an account, add items to my cart and continue to the new checkout_shipping.php page.

 

On that page my shipping and billing addresses are both correct and complete.

But under the Shipping Method (USPS) I have this error:

-2147219080 - Missing value for Country.

 

If I refresh my browser, the shipping options with prices appear. :blink:

 

Any help or ideas would be greatly appreciated!

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

  • 2 weeks later...

Hi :)

 

I have an error in catalog/admin/customers.php: Parse error: parse error, unexpected T_CASE in \catalog\admin\customers.php on line 186

 

Lines 185 and 186 are:

 

		break;
  case 'deleteconfirm':

 

I have oscommerce 2.2 RC2a, and de bug fix for this contributition installed.

 

Thanks for all :)

Link to comment
Share on other sites

Tried to add this to my shop. Changed county in the address book to US, and the states got populated with the create account page. Very strange.

 

So I had a page within a page.

 

The only think I can think of iis it has to do with line 48:

request.open("POST", 'create_account.php', true);

 

happening in address_book

 

Any ideas?

Link to comment
Share on other sites

Also, wondering if anyone has had problems with this not refreshing at times.

 

I can't seem to replicate the same error, but I did notice that the onChange had trouble changing earlier. Seems like it stalled out, and the loading gif was just waiting. Any ideas?

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

I've installed the 1.5.5 ajax version but when I go to create an account or any address page I get the spinning image in the left corner just under the breadcrumb and it spins forever. I then change my country, that works and the state is populated then the image disappears. Isn't that back to front??

 

Edit: I'm on version rc2a and copied the included files over as it's an empty development store

 

Hope someone can point me in the right direction

 

Cheers

 

Ian

Edited by ianric
Link to comment
Share on other sites

error: is the same!!!!!!!!!!!!!!!!!!!!!!!

 

 

find code (~144):

$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . tep_draw_pull_down_menu('address_format_id', tep_get_address_formats(), $cInfo->address_format_id));

 

replace with:

$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . tep_draw_pull_down_menu('address_format_id', tep_get_address_formats()));

$active_value = array('0','1');

$contents[] = array('text' => '<br>' . TEXT_INFO_ACTIVE . '<br>' . tep_draw_pull_down_menu('active',$active_value));

 

 

 

 

find code (~155):

$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . tep_draw_pull_down_menu('address_format_id', tep_get_address_formats(), $cInfo->address_format_id));

 

replace with:

$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . tep_draw_pull_down_menu('address_format_id', tep_get_address_formats(), $cInfo->address_format_id));

$active_value = array('0','1');

$contents[] = array('text' => '<br>' . TEXT_INFO_ACTIVE . '<br>' . tep_draw_pull_down_menu('active', $active_value, $cInfo->active));

Link to comment
Share on other sites

I found the problem.. kinda stupid but ah well..

 

open catalog/includes/functions/html_output.php

 

find the function tep_draw_pull_down_menu(...)

 

find the code

	  if ($default == $values[$i]['id']) {
	$field .= ' SELECTED';
  }

 

change it to

 

	  if ($default === $values[$i]['id']) {
	$field .= ' SELECTED';
  }

 

notice the === operator instead of the == operator.. thats it ..

 

J

 

Hi

 

Just thought I'd say thanks for the above fix. It worked for me

 

Cheers

 

ian

Link to comment
Share on other sites

Hi

 

I've installed the 1.5.5 ajax version but when I go to create an account or any address page I get the spinning image in the left corner just under the breadcrumb and it spins forever. I then change my country, that works and the state is populated then the image disappears. Isn't that back to front??

 

Edit: I'm on version rc2a and copied the included files over as it's an empty development store

 

Hope someone can point me in the right direction

 

Cheers

 

Ian

Hi

 

Thanks to everyone who "helped" but I managed to get it working on my self. I forgot to add the css info. :blush: The image still spins anti-clockwise but I can live with that.

 

Is it possible to collapse the div? At the moment it is leaving a gap the height of the image on the page

 

Cheers

 

ian

Link to comment
Share on other sites

I installed Country-State Selector v1.5.5 (AJAX) by just copied and pasted the php files to the site.

 

I got an error message as below

 

Fatal error: Cannot redeclare tep_show_category() (previously declared in /home/mysite/html/includes/header.php:162) in /home/mysite/html/includes/boxes/categories.php on line 59

 

Anyone know how to fix this? Thanks!

Link to comment
Share on other sites

  • 2 weeks later...
Is it possible to display the state name instead the state code?

 

Customer enters State, say Florida. Instead of having the address show "FL", what needs to be modified to display the name itself? ie "Florida"

I'm not sure which display you're referring to. This contribution affects how the state is input, not how it is displayed elsewhere in osC. That is done by the tep_format_address routine and is based on the address format. Not part of this contrib.

Link to comment
Share on other sites

Fatal error: Cannot redeclare tep_show_category() (previously declared in /home/mysite/html/includes/header.php:162) in /home/mysite/html/includes/boxes/categories.php on line 59

Do you have an include or require of categories.php in header.php? That is not standard.

Link to comment
Share on other sites

  • 2 weeks later...

The contribution supports different countries. When the customer changes the country field, the state/province field updates to show either a dropdown of the zones (states/provinces) in that country, or a text box if none are defined. Perhaps you incorrectly installed the contribution. Which version did you use?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...