Jump to content
nanorock4

Change default country dropdown list

Recommended Posts

Does anyone know how to change the country dropdown lists to default to a specific country. As you know they default to aphabetical order. I want to be able to have United States to be listed out of order at the top of the list with the others in the normal order. Is this a php edit or a SQL edit and where and how would it be done?

 

Thanks,

Edited by nanorock4

Share this post


Link to post
Share on other sites
Does anyone know how to change the country dropdown lists to default to a specific country. As you know they default to aphabetical order. I want to be able to have United States to be listed out of order at the top of the list with the others in the normal order. Is this a php edit or a SQL edit and where and how would it be done?

 

Thanks,

 

 

Ok I found it after digging through the custimization info.

 

You can also make any country appear by default while still having the pull down list available.

 

In includes/functions/html_output.php at about line 299 find:

 

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

Replace (for the United States) with...

 

// $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

$countries_array = array(array('id' => '223', 'text' => 'United States'));

 

I just commented out the original line to keep it as a reference.

You can change the country id and the text in this line to make any country appear by default.

 

 

Thanks anyway

Share this post


Link to post
Share on other sites

Hi actually you want to change the includes/languages/english.php

 

at about line 140

 

// pull down default text

define('PULL_DOWN_DEFAULT', 'United States');

Share this post


Link to post
Share on other sites
Ok I found it after digging through the custimization info.

 

You can also make any country appear by default while still having the pull down list available.

 

In includes/functions/html_output.php at about line 299 find:

 

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

Replace (for the United States) with...

 

// $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

$countries_array = array(array('id' => '223', 'text' => 'United States'));

 

I just commented out the original line to keep it as a reference.

You can change the country id and the text in this line to make any country appear by default.

Thanks anyway

 

Your method worked perfectly, thanks!

Share this post


Link to post
Share on other sites
Ok I found it after digging through the custimization info.

 

You can also make any country appear by default while still having the pull down list available.

 

In includes/functions/html_output.php at about line 299 find:

 

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

Replace (for the United States) with...

 

// $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

$countries_array = array(array('id' => '223', 'text' => 'United States'));

 

I just commented out the original line to keep it as a reference.

You can change the country id and the text in this line to make any country appear by default.

Thanks anyway

 

 

thnks a lot

Share this post


Link to post
Share on other sites

A cleaner way to do this, whilst preserving the OSCommerce languages system is:

 

in catalogue/includes/languages/english.php (& for all languages in use):

 

Change:

define('PULL_DOWN_DEFAULT', 'Please Select');

to

define('PULL_DOWN_DEFAULT', '**Default Country Here**');

 

Then below that, add:

define('PULL_DOWN_DEFAULT_VALUE', '**your country id here**');

 

 

In catalogue/includes/functions/html_output.php

 

Change:

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

To:

$countries_array = array(array('id' => PULL_DOWN_DEFAULT_VALUE, 'text' => PULL_DOWN_DEFAULT));

Share this post


Link to post
Share on other sites
A cleaner way to do this, whilst preserving the OSCommerce languages system is:

 

in catalogue/includes/languages/english.php (& for all languages in use):

 

Change:

define('PULL_DOWN_DEFAULT', 'Please Select');

to

define('PULL_DOWN_DEFAULT', '**Default Country Here**');

 

Then below that, add:

define('PULL_DOWN_DEFAULT_VALUE', '**your country id here**');

In catalogue/includes/functions/html_output.php

 

Change:

$countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));

 

To:

$countries_array = array(array('id' => PULL_DOWN_DEFAULT_VALUE, 'text' => PULL_DOWN_DEFAULT));

 

FYI I did the above and it made the default for my Manufactures list United States. So this is not a working solution.

Share this post


Link to post
Share on other sites
FYI I did the above and it made the default for my Manufactures list United States. So this is not a working solution.

 

Just had the same problem i'd select United Kingdom and it would show up as United States - turned out that the array 'id' => '223' was causing it to switch to United States - even if you change the text after. So to change it for other countries you need the number. In my case the UK was 222 so the resulting code is:

 

$countries_array = array(array('id' => '222', 'text' => 'United Kingdom'));

 

so the id and the text have now been changed. To find the others I think you can use view source on the resulting page, or just guess.

Share this post


Link to post
Share on other sites
Does anyone know how to change the country dropdown lists to default to a specific country. As you know they default to aphabetical order. I want to be able to have United States to be listed out of order at the top of the list with the others in the normal order. Is this a php edit or a SQL edit and where and how would it be done?

 

Thanks,

you can use the active countries

http://www.oscommerce.com/community/contributions,3607

Share this post


Link to post
Share on other sites

is there a way to bring my 3 neighborhood countrys on top and the others down?

 

please choose:

germany

austria

swiss

---------

rest of the world

spain

usa

...

...

...

.

Share this post


Link to post
Share on other sites

Hi guys,

 

here's the problem: I just modified the all files and everything seems to be ok except 2 files that I realy don't know how to figured out

 

files: 1. check_out_shipping.php (when you want to add a new shipping address)

2. checkout_payment_address.php (When you want to add a new Billing address)

 

does anyone know how to change the state filed to have pre-selected the state that I want (not country, that one I have fix it)

 

any help will be nice :)

Edited by d_paulo

Share this post


Link to post
Share on other sites

here's the code from the checkout_shipping_address.php

 

 

<?php
  $radio_buttons = 0;

  $addresses_query = tep_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "'");
  while ($addresses = tep_db_fetch_array($addresses_query)) {
	$format_id = tep_get_address_format_id($addresses['country_id']);
?>

 

Where can set the default state/provincie id ?

Edited by d_paulo

Share this post


Link to post
Share on other sites
here's the code from the checkout_shipping_address.php

<?php
  $radio_buttons = 0;

  $addresses_query = tep_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "'");
  while ($addresses = tep_db_fetch_array($addresses_query)) {
	$format_id = tep_get_address_format_id($addresses['country_id']);
?>

 

Where can set the default state/provincie id ?

 

 

Add

 

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

 

Above

 

 $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);

 

and change to

 

 $zones_array[] .= array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);

 

NOTE the

.=

 

in create_account.php and any other pages that need it.

Edited by WS Evolution

Share this post


Link to post
Share on other sites

Sorry the code should be like this for it to work correctly:

 

 

 

	$zones_array[] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);
	while ($zones_values = tep_db_fetch_array($zones_query)) {

	  $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);

	}

Share this post


Link to post
Share on other sites

I have found the simplest way to set a default country is to make the following change to includes/functions/html_output.php on or around line 303..

 

Look for: function tep_get_country_list($name, $selected = '', $parameters = '') {

 

Change $selected = '' to $selected = '223' so it looks like this...

 

function tep_get_country_list($name, $selected = '223', $parameters = '') {

 

That would make USA the default country. For those in other countries just substitute 223 with your country.

Share this post


Link to post
Share on other sites

I tried various ways to output a sorted countries list, changing the country I wanted at top to be ID 0 and whatnot, didnt work. Finally I relaized I was overlooking the obvious of using <option .... selected>

 

Thankfully, the requisite functions have built-in "selected" handling, thus setting your default country is easy.

 

Edit create_account.php and find

CODE

<tr>

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

<td class="main"><?php echo tep_get_country_list('country') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

</tr>

 

 

you want to change this line

CODE

php echo tep_get_country_list('country') .

 

to be

CODE

php echo tep_get_country_list('country','223') .

 

223 == the country ID for United States. YOu can set that to be any country by looking either in the database countries list for your countries ID, or even easier, look at the HTML of the create_account.php page and find where the country drop down list is, search for your country and grab the "value".

Share this post


Link to post
Share on other sites

Here is an interesting fix for several of the requests in this thread, although it does require a modification to the "countries" table in your DB.

 

Add a column named "countries_sort" that's type "int" and an appropriate length for a default within which you can fully enumerate the countries you want at the top of the list.  So if you want 3 countries at the top, your default will be set at "4".  Then go in and enumerate in order the countries you want at the top of the list, starting with 0 for the top, 1 for second, etc.

 

Then just go into general.php and find (ctrl+f) the function "tep_get_countries."  There's an if, followed by two 'else' statements, and a query for each.  In the last query, add "countries_sort, " to the 'select' statement, and change the 'order by' to "order by countries_sort, countries_name"

 

That will cause the countries drop down to retain the initial blank, but when the drop down button is pushed, the countries you chose to specify first will be at the top of the list.  

 

This way, it doesn't screw with the mechanics, it just changes the order of the array that holds all the countries.

Share this post


Link to post
Share on other sites

And eh...since I'm resurrecting an ancient thread...I might toss this question in:

 

How would a guy go about making the states drop-down populate 'onclick' of a country from its drop-down?  Seems silly to have to submit an incomplete form just to get the right array of states. We could move the country up before the state selection and the whole thing would flow better.

Share this post


Link to post
Share on other sites

An easy work around: I just added a blank space in front of the country name and voila, it appears first. and It is not very noticeable.
I guess one could add two spaced and three spaces to have three countries appearing in a certain order.

Edited by zocla

Share this post


Link to post
Share on other sites

@@zocla  Did you test that in all modern browsers? The last time I checked, some browsers did not work with that trick.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

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

×