Jump to content



Photo
- - - - -

Setting default country in countries drop down


This topic has been archived. This means that you cannot reply to this topic.
36 replies to this topic

#1   dontera

dontera
  • Members
  • 19 posts

Posted 26 March 2004 - 21:36

This is something I had wrestled with for some time, until the obvious hit me..

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

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

you want to change this line
php echo tep_get_country_list('country') .
to be
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".

Hope this helps.

#2   Bruin_03

Bruin_03
  • Members
  • 219 posts

Posted 05 April 2004 - 21:18

Ah, just what I was looking for. Thank you. /smile.gif' class='bbc_emoticon' alt=':)' />

#3   Bruin_03

Bruin_03
  • Members
  • 219 posts

Posted 05 April 2004 - 21:20

[duplicate post ]

Edited by Bruin_03, 05 April 2004 - 21:20.


#4   efficiondave

efficiondave
  • Members
  • 20 posts

Posted 07 April 2004 - 22:47

So is there a way to make US states drop down appear initially? Otherwise it makes the user go back and select it after they submit... can be confusing.

#5   efficiondave

efficiondave
  • Members
  • 20 posts

Posted 07 April 2004 - 23:40

In addition, you'll also have edit /includes/modules/address_book_details.php to change the following line:

<td class="main"><?php echo tep_get_country_list('country', $entry['entry_country_id']) . '&nbsp;' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

to:

<td class="main"><?php echo (($entry['entry_country_id'] == '') ? tep_get_country_list('country', 223) : tep_get_country_list('country', $entry['entry_country_id'])) . '&nbsp;' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

Edited by efficiondave, 07 April 2004 - 23:41.


#6   mutter

mutter
  • Members
  • 138 posts

Posted 08 April 2004 - 04:22

Hi, to add the drop down list of your country states in create_account.php.

I changed this:

<?php
      if ($process == true) {
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name 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_name'], 'text' => $zones_values['zone_name']);        }
        echo tep_draw_pull_down_menu('state', $zones_array);
      } else {
        echo tep_draw_input_field('state');
      }
    } else {
      echo tep_draw_input_field('state');
    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?>

To:

<?php
//    if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
      $revisar = tep_db_fetch_array($revisar_query);
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
        while ($zones_values = tep_db_fetch_array($zones_query)) {
          $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);        }
        echo tep_draw_pull_down_menu('state', $zones_array);
      } else {
        echo tep_draw_input_field('state');
      }
//    } else {
//      echo tep_draw_input_field('state');
//    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?>


#7   mutter

mutter
  • Members
  • 138 posts

Posted 08 April 2004 - 04:23

ohh, 138 is for Mexico, change the country id number in the code to your country id.

bye...

#8   mutter

mutter
  • Members
  • 138 posts

Posted 08 April 2004 - 04:40

To the modules/addres_book_details.php

I change this:

<?php
     if ($process == true) {
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name 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_name'], 'text' => $zones_values['zone_name']);
        }
        echo tep_draw_pull_down_menu('state', $zones_array);
      } else {
        echo tep_draw_input_field('state');
      }
    } else {
      echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

To:

<?php
 //   if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
      $revisar = tep_db_fetch_array($revisar_query);
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
        while ($zones_values = tep_db_fetch_array($zones_query)) {
          $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
        }
        echo tep_draw_pull_down_menu('state', $zones_array, tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
      } else {
        echo tep_draw_input_field('state');
      }
//    } else {
//      echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
//    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>


#9   pinbrook

pinbrook
  • Members
  • 65 posts

Posted 14 April 2004 - 19:59

I want to ship to one country only, what's the best way to acheive this?

#10   bluepony

bluepony
  • Members
  • 466 posts

Posted 15 April 2004 - 14:07

You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to.

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php
I'd rather be flying!

#11   PopTheTop

PopTheTop
  • Members
  • 886 posts

Posted 02 October 2004 - 15:40

In the pull-down list of US states, where can I edit this list? I can not find them.
L8r,
PopTheTop

Published osC Contributions:
- eCheck Payment Module v3.1
- Reviews in Product Display v2.0
- Fancier Invoice & Packingslip v6.1
- Admin Notes / Customer Notes v2.2
- Customer Zip & State Validation v2.2
- Search Box with Dropdown Category Menu v1.0

Pop your camper's top today!
It's a popup thing...
You wouldn't understand

#12   pcwaredirect

pcwaredirect
  • Members
  • 50 posts

Posted 15 January 2005 - 07:21

To the modules/addres_book_details.php

I change this:

<?php
     if ($process == true) {
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name 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_name'], 'text' => $zones_values['zone_name']);
        }
        echo tep_draw_pull_down_menu('state', $zones_array);
      } else {
        echo tep_draw_input_field('state');
      }
    } else {
      echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

To:

<?php
 //   if ($process == true) {
$revisar_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = 138");
      $revisar = tep_db_fetch_array($revisar_query);
      $entry_state_has_zones = ($revisar['total'] > 0);
      if ($entry_state_has_zones == true) {
        $zones_array = array();
        $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = 138 order by zone_name");
        while ($zones_values = tep_db_fetch_array($zones_query)) {
          $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
        }
        echo tep_draw_pull_down_menu('state', $zones_array, tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
      } else {
        echo tep_draw_input_field('state');
      }
//    } else {
//      echo tep_draw_input_field('state', tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']));
//    }

    if (tep_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT;
?></td>

<{POST_SNAPBACK}>


why do you edit the address_book_details.php ? Is this necessary? i made my state drop down box using something different but it never mentioned having to edit the address book. is this ok?

Jeremy

#13   Analyser

Analyser
  • Members
  • 19 posts

Posted 29 January 2005 - 17:07

So helpful, just what I needed, thanks

Edited by Analyser, 29 January 2005 - 17:08.


#14   atouk

atouk
  • Members
  • 30 posts

Posted 29 January 2005 - 17:54

Most excellent thread!

The only thing that got me was not changing the country code for the state dropdown to 223 (US) from 138 (Mexico) after a straight cut and paste of the code.

OSC Lesson #654: Pay attention to what you are pasting, even if it seems simple.

#15   NeoNiko

NeoNiko
  • Members
  • 88 posts

Posted 06 May 2005 - 00:31

Bluepony -
Could you post how you did that? That sounds like a really cool idea and I would love to give it a try.
Thank you,
NeoNiko

#16   Earth Bizz

Earth Bizz
  • Validating
  • 43 posts

Posted 31 July 2005 - 22:52

Anyway to delete the Country drop down box alltogether and hardcode just one Country into the create_account file?

I'm an ex Cube cart user and I did it there .. but I'm still a newbie to OC .. not sure if its possible.

/rolleyes.gif' class='bbc_emoticon' alt=':rolleyes:' />
May you live long & prosper in interesting times (Spock/Confucious)

#17   tsheffie

tsheffie
  • Members
  • 4 posts

Posted 16 August 2005 - 10:57

You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to. 

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php

<{POST_SNAPBACK}>


That sounds pretty cool but can you give a bit more detail. Some of us aren't quite up to your speed. /blink.gif' class='bbc_emoticon' alt=':blink:' />

#18   dnfhosting

dnfhosting
  • Members
  • 3 posts

Posted 20 October 2005 - 18:10

You could just delete the other countries, but then if you ever change your mind you would have to load back in the countries you want to ship to.

I set a filter on my site. I just added another column to the Countries table called Show_Country (int) and then marked the ones that I wanted to include with a 1.

Then I just added that condition (WHERE Show_Country=1) to the SQL statement in the tep_get_countries function in includes/functions/general.php


Hi bluepony,
I added the table column, but am not sure where to add the sql statement (i.e. which line(s)). I tried several things and none worked, so if you could specify where the WHERE goes, it would be greatly appreciated.

Thanks!

#19   scranmer

scranmer
  • Members
  • 172 posts

Posted 14 December 2005 - 08:40

edit create_account... edit address_book....

/dry.gif' class='bbc_emoticon' alt='<_<' /> NO NEED! /thumbsup.gif' class='bbc_emoticon' alt=':thumbsup:' />

Just edit includes\functions\html_output.php and amend the following bit to default ALL country LOVs to your shops country.

HTH

Si.


////
// Creates a pull-down list of countries
  function tep_get_country_list($name, $selected = '', $parameters = '') {

//**si**
if ( strlen($selected)==0 ) $selected = STORE_COUNTRY;
//**si**

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

	for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
	  $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
	}

	return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
  }


#20   bmw000

bmw000
  • Members
  • 28 posts

Posted 13 May 2007 - 23:37

This was an easy change, both for the country and state dropdown edits.

I think one more edit would make it perfect.

With the new state drop down mod, how can it be made to default to "Please Select" in lieu of Alabama?

I noticed that "Please select" is not in the list at all.

How can I add "Please select" to the state dropdown and make that the default selection?

Thanks,
Brian

Edited by bmw000, 13 May 2007 - 23:38.