Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

chang country appearance order in country dropdown list


gogowanda

Recommended Posts

hi all, how can i bring up US and Canada to the top of the country dropdown list? i tried to change the table of "countries" but nothing changed...any help would be greatly appreciated.

this brings a general question i had - does OSC constructed MySql database entries/structure?

Link to comment
Share on other sites

I first went through and deleted all of the countries that I have no plans of ever shipping anything to which was about 200 of the 220+ countries to narrow down the list a bit. I then went and switched the countries_id for the US and Canada to be the first two countries_id in the database. Then went to catalog/includes/functions/general.php and changed the tep_get_countries function to order by countries_id rather than by countries_name so it now looks like this (the only change was the two "order by" statements:

 

////

// Returns an array with countries

// TABLES: countries

 function tep_get_countries($countries_id = '', $with_iso_codes = false) {

   $countries_array = array();

   if (tep_not_null($countries_id)) {

     if ($with_iso_codes == true) {

       $countries = tep_db_query("select countries_name, countries_iso_code_2, countries_iso_code_3 from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "' order by countries_id");

       $countries_values = tep_db_fetch_array($countries);

       $countries_array = array('countries_name' => $countries_values['countries_name'],

                                'countries_iso_code_2' => $countries_values['countries_iso_code_2'],

                                'countries_iso_code_3' => $countries_values['countries_iso_code_3']);

     } else {

       $countries = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where countries_id = '" . (int)$countries_id . "'");

       $countries_values = tep_db_fetch_array($countries);

       $countries_array = array('countries_name' => $countries_values['countries_name']);

     }

   } else {

     $countries = tep_db_query("select countries_id, countries_name from " . TABLE_COUNTRIES . " order by countries_id");

     while ($countries_values = tep_db_fetch_array($countries)) {

       $countries_array[] = array('countries_id' => $countries_values['countries_id'],

                                  'countries_name' => $countries_values['countries_name']);

     }

   }



   return $countries_array;

 }

 

So now the US shows up first in the drop down, Canada second, and the rest alphabetically as their countries_id was not changed and they happen to be listed in alphabetical order. :) HTH

Link to comment
Share on other sites

thanks pal, two questions though (dude im really trying...)

 

1. how can i delete countries without del them one by one from osc admin? can i do a faster del from database directly?

 

2. how can i edit country ID? from MySql?

 

thanks!

Link to comment
Share on other sites

thanks pal, two questions though (dude im really trying...)

 

1. how can i delete countries without del them one by one from osc admin? can i do a faster del from database directly?

 

2. how can i edit country ID? from MySql?

 

thanks!

 

It is much faster and easier to figure out what ones you would like to keep and then just delete the rest in one query. This thread will help out some, just make sure you read the whole thing as if you run the first query listed you will delete the whole table :eek:

 

http://www.oscommerce.com/forums/viewtopic.php?t=42867

 

If you don't already have it installed you might want to look into a database management tool ie. phpMyAdmin where you can easily manipulate your DB. http://phpmyadmin.net If you have some type of Cpanel you most likely already have it installed, if not you can download it free through the above site, configure it according to the instructions and upload it to your server etc.

Link to comment
Share on other sites

I didn't modify any of the files but just changed the country_id in the table for the US to 1. When going into checkout I got an error with the USPS module in calculating the shipping. Is there something else that needs to be done to get the shipping module to work correctly?

 

Thanks,

Deb

Link to comment
Share on other sites

First, Back Up your database. Next go into TABLE_ZONES and change all of the "223"s/zone_country_ids for the US to be the same as whatever you changed the country_id to, in this case I think you changed it to "1".

Link to comment
Share on other sites

Thanks for the input Justin. I got the pull down menus with the us and canada on top, however, I'm still getting a "-2147219080 - Missing value for Country." Do you know what else I need to do?

 

thanks

Deb

Link to comment
Share on other sites

Found a few more things to change...I don't use USPS so didn't have to do all of these changes. Anyway go into your TABLE_CONFIGURATION and change both SHIPPING_ORIGIN_COUNTRY (configuration_id=98 ) to a configuration_value matching your country_id (1 in this case) instead of 223, also change the STORE_COUNTRY (configuration_id=5) to a configuration_value of "1" instead of 223. Hopefully that will be it... :oops:

Link to comment
Share on other sites

Still working on this so I can get it like I want it. I hate it that OSC no longer lets you default to which country shows up. In older versions it would default to the country in which your store is located. It no longer does this, nor does it recognize the state abbreviations ie. if I type in MI for Michigan it gives me an error and asks me to select from the drop down. This IMO, is completely unacceptable so I will try to get it to work like an e-commerce store should work. For starters to get it to default to the country your store is located in do this:

 

In catalog/create_account.php around line 15 find this:

// needs to be included earlier to set the success message in the messageStack

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CREATE_ACCOUNT);

 

Place this just below it:

$account['entry_country_id'] = STORE_COUNTRY;

 

Around line 440 find this:

              <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>

 

Replace it with this:

              <tr>

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

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

             </tr>

 

Now to go work on the whole state issue....

Link to comment
Share on other sites

Will this also work if they change the shipping address in the shopping cart/checkout procedure? Or, do I need to go and make similar changes in the edit address files as well?

 

Thanks for all your help. By the time I'm finished with all of this editing, I might just know how to write in php :shock:

 

Deb

Link to comment
Share on other sites

OK, to get it to recognize the state abbreviations rather than give the customer an error message with the drop down you simply need to comment out this section in three files:

 

catalog/create_account.php

catalog/checkout_payment_address.php

catalog/checkout_shipping_address.php

 

Like this:

/*    if (ACCOUNT_STATE == 'true') {

     $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('create_account', ENTRY_STATE_ERROR_SELECT);

       }

     } else {

       if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {

         $error = true;



         $messageStack->add('create_account', ENTRY_STATE_ERROR);

       }

     }

   }

*/

 

For whatever reason this portion does not work properly as it is not recognizing zone_code:

$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) . "%')");

Link to comment
Share on other sites

:D Justin, thanks SO MUCH. Finally got the shopping cart working. Just had to go in and change the table address book so that some of the people who have already created an account wouldn't get the USPS error.

 

I added just the $account['entry_country_id'] = STORE_COUNTRY; to the checkout_shipping_address because, in my ignorance, I didn't know what else to change. But, seems to work great. Those are the only places I could think of where the address gets changed. If there is somewhere else I guess I'll find out about it later when I do a more thorough test.

 

Look forward to hearing about how the state changes go. I did notice when I was in the table address_book that the state fields were empty yet the zone id was there for the state. Are you posting them elsewhere?

 

Thanks again,

 

Deb

Link to comment
Share on other sites

  • 1 month later...
Still working on this so I can get it like I want it. For starters to get it to default to the country your store is located in do this:

 

Now to go work on the whole state issue....

Justin,

Thank you so much for this change,,

Regards

Tom

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...