Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Wc&dc Which Countries And Default Country


GM1

Recommended Posts

This will be the support forum for WC&DC.

 

Gord.

 

 

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

WC&DC Which Countries and Default Country

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

 

Sure we all want to go global but starting up a web shop is difficult enough without having to worry about: accepting payment from, creating customs forms for, and shipping to many international countries. This is a simple hack to reduce the number of countries that you sell to but allow you to add them back very easily in the future.

 

It creates a new show_country field in the countries table in your database to indicate whether or not the country should be listed in your country drop down lists. Then the code that creates that drop down list is edited to look at this field.

 

Optionally you can also tweak the default country that shows up in the drop down list via another simple hack that tweaks the code that displays the country drop down list.

 

Based upon the following tips and tricks thread:

http://www.oscommerce.com/forums/index.php?showtopic=85405

 

GM1

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

 

Step 1 - Which Countries

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

(inspired by post by bluepony)

 

i) edit countries.sql (included in this contribution).

read the comments/instructions and add in the countries you desire. Note in

the example that you can either specify the country id (which you can

determine by browsing the countries table via phpmyadmin) or you can specify

the country name in quotes (which you can determine by exactly copying the

country name that is displayed in the drop down menu on the oscommerce

default install - check oscommerce site if yours is not displaying all

countries). Add as many countries as you like by simply copying and pasting

the ADD line and changing the country id or name in each line.

 

For reference here is the contents of countries.sql:

#uncomment the next line if running for the first time, comment it if show_country already exists (ie if you have run it once already)

ALTER TABLE `countries` ADD `show_country` TINYINT (1) UNSIGNED DEFAULT '0' NOT NULL;

#use either of the following to add via country name or via country id

#add as many countries as you like this way by adding more lines

UPDATE countries SET show_country=1 where countries_name="Canada";

UPDATE countries SET show_country=1 where countries_id=223;

 

ii) via phpmyadmin:

1) select your database

2) click on the import tab

3) browse to countries.sql

4) click on go

 

if all goes well you should have the new column show_country added to your

countries table and the countries you wish to use have a 1 in that field. You

can add more countries in the future by modifying the countries.sql file and

re-running it in phpmyadmin. For subsequent runs remember to comment out

the line which creates the new show_country field.

 

Step 2 - Which Countries

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

Now you want to tweak the code that builds the array of country names. For database queries you want to add "where show_country=1". If there already is a "where" in the query you will have to add it like "where show_country=1 AND where..."

 

Edit catalog/includes/functions, find tep_get_countries and comment it out

and replace with the following (merge in any changes you have in this function if appropriate).

 

Note the lines preceded by # are the original versions prior to the hack which simply adds the "where show_country=1" to them.

 

 

// 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_name");

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

$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 = tep_db_query("select countries_name from " . TABLE_COUNTRIES . " where show_country=1 AND 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_name");

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

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;

}

 

 

Optional Step 3 - Default Country

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

 

(thanks to post by scranmer)

 

This step makes a very simple tweak to set the default country that shows up in the country pull down. In this example it sets it to the constant STORE_COUNTRY which is defined in your admin panel under configuration/my store/country. But you can change this to any valid country id say 223 (USA) if your store was in Canada but you wanted the default selector to be USA for example. Again country ids can be browsed via phpmyadmin. This should be obvious: you must have show_country=1 (see above step 1) for the country you set up as default if you have done the which countries hack (steps 1 and 2 above).

 

Note also that this tweak is independent from the which countries hack above so if you just want default country, skip steps 1 and 2 and just do this.

 

Edit includes/functions/html_ouptput.php and find tep_get_country_list

and add the three line tweak shown below (or comment out your old function and add this one in its place):

 

////

// Creates a pull-down list of countries

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

 

#default country hack begin

if ( strlen($selected)==0 ) $selected = STORE_COUNTRY;

#default country hack end

 

$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);

}

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.
Note: Your post will require moderator approval before it will be visible.

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