Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Currency associated with customer


ashna

Recommended Posts

Posted

Hello Everyone,

 

Just wanted to know if one can set things in such a way for currency, that customer makes a currency choice and this way whenever the customer is logged in he/she gets the currency of his/her choice. If the customer is not logged then the stores default currency is shown.

 

was thinking even if the customer is logged in still one should be able to show the customers currency of choice with the help of cookies.

 

I am not a coder, just a thought. Let m know if someone has done this. would be really nice to have such a feature.

 

Ashwani

Posted
Hello Everyone,

 

Just wanted to know if one can set things in such a way for currency, that customer makes a currency choice and this way whenever the customer is logged in he/she gets the currency of his/her choice. If the customer is not logged then the stores default currency is shown.

 

was thinking even if the customer is logged in still one should be able to show the customers currency of choice with the help of cookies.

 

I am not a coder, just a thought. Let m know if someone has done this. would be really nice to have such a feature.

 

Ashwani

 

well, then you need to add the currency to the customer table and fetch and update that whenever the customer changes currencies.

 

personally, I set the default currency and country (for create account) based on the browser language settings.

Treasurer MFC

Posted

Thanks for the reply.It does solves the issue upto a certain extent, I will be happy with this. I have to admit that I am not a php expert.

 

Any ideas how it can be achieved.

 

Thanks

Ashwani

Posted
Thanks for the reply.It does solves the issue upto a certain extent, I will be happy with this. I have to admit that I am not a php expert.

 

Any ideas how it can be achieved.

 

Thanks

Ashwani

 

 

well, you add this function to includes/functions/general.php:

 

you give this function the language code from the browser.

it returns either the country name or the osc country code based on the $give_code parameter.

 

The latter I use set the default country for the listbox in create account and such.

Note that I only have put in the codes for the countries I support, all others default to 206 Taiwan in my case.

 

 

function tep_get_country_by_language($country_code, $give_code = false) {

 

$code1 = substr($country_code,0,2);

$code2 = substr($country_code,3,2);

$country_name = '';

$ctry_code = '';

 

if ($code1 == "af") {$country_name = 'Afrikaans';

} elseif ($code1 == "ar") {$country_name = 'Arabic';

if ($code2 == "ae") {$country_name = 'UAE'; $ctry_code = 221;}

if ($code2 == "bh") {$country_name = 'Bahrain';$ctry_code = 17;}

if ($code2 == "eg") {$country_name = 'Egypt';$ctry_code = 63;}

if ($code2 == "dz") {$country_name = 'Algeria';}

if ($code2 == "iq") {$country_name = 'Iraq';}

if ($code2 == "jo") {$country_name = 'Jordan';}

if ($code2 == "kw") {$country_name = 'Kuwait';$ctry_code = 114;}

if ($code2 == "lb") {$country_name = 'Lebanon';}

if ($code2 == "ly") {$country_name = 'Libya';}

if ($code2 == "ma") {$country_name = 'Morocco';}

if ($code2 == "om") {$country_name = 'Oman';}

if ($code2 == "qa") {$country_name = 'Qatar';}

if ($code2 == "sa") {$country_name = 'Saudi';$ctry_code = 184;}

if ($code2 == "sy") {$country_name = 'Syria';}

if ($code2 == "tn") {$country_name = 'Tunisia';}

if ($code2 == "ye") {$country_name = 'Yemen';}

} elseif ($code1 == "be") {$country_name = 'Belarusian';

} elseif ($code1 == "bg") {$country_name = 'Bulgarian';

} elseif ($code1 == "ca") {$country_name = 'Catalan';

} elseif ($code1 == "cs") {$country_name = 'Czech';$ctry_code = 56;

} elseif ($code1 == "da") {$country_name = 'Denmark';$ctry_code = 57;

} elseif ($code1 == "de") {$country_name = 'Germany';$ctry_code = 81;

if ($code2 == "at") {$country_name = 'Austria';$ctry_code = 14;}

if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

if ($code2 == "li") {$country_name = 'Liechtenstein';$ctry_code = 122;}

if ($code2 == "lu") {$country_name = 'Luxembourg';$ctry_code = 124;}

} elseif ($code1 == "el") {$country_name = 'Greece';$ctry_code = 84;

} elseif ($code1 == "en") {$country_name = 'Other English';$ctry_code = 223;

if ($code2 == "us") {$country_name = 'USA';$ctry_code = 223;}

if ($code2 == "au") {$country_name = 'Australia';$ctry_code = 13;}

if ($code2 == "bz") {$country_name = 'Belize';}

if ($code2 == "ca") {$country_name = 'Canada';$ctry_code = 38;}

if ($code2 == "gb") {$country_name = 'UK';$ctry_code = 222;}

if ($code2 == "ie") {$country_name = 'Ireland';$ctry_code = 103;}

if ($code2 == "jm") {$country_name = 'Jamaica';}

if ($code2 == "nz") {$country_name = 'New Zealand';$ctry_code = 153;}

if ($code2 == "tt") {$country_name = 'Trinidad';}

if ($code2 == "za") {$country_name = 'South Africa';$ctry_code = 193;}

} elseif ($code1 == "es") {$country_name = 'Spain';$ctry_code = 195;

if ($code2 == "ar") {$country_name = 'Argentina';$ctry_code = 10;}

if ($code2 == "bo") {$country_name = 'Bolivia';}

if ($code2 == "cl") {$country_name = 'Chile';}

if ($code2 == "co") {$country_name = 'Colombia';}

if ($code2 == "cr") {$country_name = 'Costa Rica';}

if ($code2 == "do") {$country_name = 'Dominican';}

if ($code2 == "ec") {$country_name = 'Ecuador';}

if ($code2 == "gt") {$country_name = 'Guatemala';}

if ($code2 == "hn") {$country_name = 'Honduras';}

if ($code2 == "mx") {$country_name = 'Mexico';$ctry_code = 138;}

if ($code2 == "ni") {$country_name = 'Nicaragua';}

if ($code2 == "pa") {$country_name = 'Panama';}

if ($code2 == "pe") {$country_name = 'Peru';}

if ($code2 == "pr") {$country_name = 'Puerto Rico';}

if ($code2 == "py") {$country_name = 'Paraguay';}

if ($code2 == "sv") {$country_name = 'El Salvador';}

if ($code2 == "uy") {$country_name = 'Uruguay';}

if ($code2 == "ve") {$country_name = 'Venezuela';}

} elseif ($code1 == "et") {$country_name = 'Estonian';

} elseif ($code1 == "eu") {$country_name = 'Basque';

} elseif ($code1 == "fa") {$country_name = 'Farsi';

} elseif ($code1 == "fi") {$country_name = 'Finland';$ctry_code = 72;

} elseif ($code1 == "fo") {$country_name = 'Faeroes';

} elseif ($code1 == "fr") {$country_name = 'France';$ctry_code = 73;

if ($code2 == "be") {$country_name = 'Belgium';$ctry_code = 21;}

if ($code2 == "ca") {$country_name = 'Canada';$ctry_code = 38;}

if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

if ($code2 == "ca") {$country_name = 'Luxembourg';$ctry_code = 124;}

} elseif ($code1 == "gd") {$country_name = 'Scotland';$ctry_code = 222;

if ($code2 == "ie") {$country_name = 'Ireland';}

} elseif ($code1 == "he") {$country_name = 'Hebrew';

} elseif ($code1 == "hi") {$country_name = 'Hindi';

} elseif ($code1 == "hr") {$country_name = 'Croatian';

} elseif ($code1 == "hu") {$country_name = 'Hungarian';$ctry_code = 97;

} elseif ($code1 == "in") {$country_name = 'Indonesian';$ctry_code = 100;

} elseif ($code1 == "is") {$country_name = 'Icelandic';$ctry_code = 98;

} elseif ($code1 == "he") {$country_name = 'Hebrew';$ctry_code = 104;

} elseif ($code1 == "it") {$country_name = 'Italy';$ctry_code = 105;

if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

} elseif ($code1 == "ja") {$country_name = 'Japan';$ctry_code = 107;

} elseif ($code1 == "ji") {$country_name = 'Yiddish';$ctry_code = 104;

} elseif ($code1 == "ko") {$country_name = 'Korea';

} elseif ($code1 == "lt") {$country_name = 'Lithuania';

} elseif ($code1 == "lv") {$country_name = 'Latvian';

} elseif ($code1 == "mk") {$country_name = 'Macedonia';

} elseif ($code1 == "ms") {$country_name = 'Malaysia';$ctry_code = 129;

} elseif ($code1 == "mt") {$country_name = 'Malta';$ctry_code = 132;

} elseif ($code1 == "nl") {$country_name = 'Netherlands';$ctry_code = 150;

if ($code2 == "be") {$country_name = 'Belgium';$ctry_code = 21;}

} elseif ($code1 == "no") {$country_name = 'Norway';$ctry_code = 160;

} elseif ($code1 == "pl") {$country_name = 'Poland';$ctry_code = 170;

} elseif ($code1 == "pt") {$country_name = 'Portugual';$ctry_code = 171;

if ($code2 == "br") {$country_name = 'Brazil';$ctry_code = 30;}

} elseif ($code1 == "rm") {$country_name = 'Romania';

} elseif ($code1 == "ro") {$country_name = 'Romania';

} elseif ($code1 == "ru") {$country_name = 'Russia';

} elseif ($code1 == "sb") {$country_name = 'Sorbian';

} elseif ($code1 == "sk") {$country_name = 'Slovak';

} elseif ($code1 == "sl") {$country_name = 'Slovenian';

} elseif ($code1 == "sq") {$country_name = 'Albania';

} elseif ($code1 == "sr") {$country_name = 'Serbia';

} elseif ($code1 == "sv") {$country_name = 'Sweden';$ctry_code = 203;

if ($code2 == "fi") {$country_name = 'Finland';$ctry_code = 72;}

} elseif ($code1 == "sx") {$country_name = 'Sutu';

} elseif ($code1 == "sz") {$country_name = 'Sami';

} elseif ($code1 == "tn") {$country_name = 'Tswana';

} elseif ($code1 == "tr") {$country_name = 'Turkey';

} elseif ($code1 == "ts") {$country_name = 'Tsonga';

} elseif ($code1 == "uk") {$country_name = 'Ukrainian';

} elseif ($code1 == "th") {$country_name = 'Thailand';$ctry_code = 209;

} elseif ($code1 == "ur") {$country_name = 'Urdu';

} elseif ($code1 == "ve") {$country_name = 'Venda';

} elseif ($code1 == "vi") {$country_name = 'Vietnam';

} elseif ($code1 == "xh") {$country_name = 'Xhosa';

} elseif ($code1 == "zh") {$country_name = 'China';$ctry_code = 44;

if ($code2 == "cn") {$country_name = 'China';$ctry_code = 44;}

if ($code2 == "hk") {$country_name = 'Hong Kong';$ctry_code = 96;}

if ($code2 == "sg") {$country_name = 'Singapore';$ctry_code = 188;}

if ($code2 == "tw") {$country_name = 'Taiwan';$ctry_code = 206;}

} elseif ($code1 == "zu") {$country_name = 'Zulu';}

 

// if all fails

if ($country_name == '') {$country_name = 'Taiwan';}

if ($ctry_code == '') {$ctry_code = '206';}

 

if ($give_code) {

return ($ctry_code);

} else {

return ($country_name);

}

}

 

 

then in application_top.php

 

after :

 

if (!tep_session_is_registered('language') || ($given_language != '')) {

if (!tep_session_is_registered('language')) {

tep_session_register('language');

tep_session_register('languages_id');

}

 

include(DIR_WS_CLASSES . 'language.php');

 

 

you add:

 

$given_language = $_GET['language'];

 

if ($given_language != '') {

$lng = new language($given_language);

$language = $lng->language['directory'];

$languages_id = $lng->language['id'];

else {

$lng->get_browser_language();

$language = $lng->language['directory'];

$languages_id = $lng->language['id'];

 

// get client language setting

$browser_language = getenv('HTTP_ACCEPT_LANGUAGE');

$your_country = tep_get_country_by_language($browser_language, false); // return the country name

 

if ($lng->language['directory'] == 'english') {

// set first supported currency based on browser language setting for english & unsupported languages

switch ($your_country) {

case 'Japan' : $currency = 'JPY';break;

case 'China' : $currency = 'CNY';break;

case 'Hong Kong' : $currency = 'HKD';break;

case 'Netherlands' : $currency = 'EUR';break;

case 'Italy' : $currency = 'EUR';break;

case 'Spain' : $currency = 'EUR';break;

case 'Belgium' : $currency = 'EUR';break;

case 'Austria' : $currency = 'EUR';break;

case 'Germany' : $currency = 'EUR';break;

case 'Greece' : $currency = 'EUR';break;

case 'Finland' : $currency = 'EUR';break;

case 'Sweden' : $currency = 'EUR';break;

case 'Norway' : $currency = 'EUR';break;

case 'Denmark' : $currency = 'EUR';break;

case 'France' : $currency = 'EUR';break;

case 'Australia' : $currency = 'AUD';break;

case 'UK' : $currency = 'GBP';break;

default : $currency = 'USD';

}

}

 

if ($lng->language['directory'] == 'tchinese') {

// set first supported currency based on browser language setting for english/unsupported languages

switch ($your_country) {

case 'China' : $currency = 'CNY';break;

case 'Hong Kong' : $currency = 'HKD';break;

default : $currency = 'TWD';

}

}

 

if (!tep_session_is_registered('currency')) {

tep_session_register('currency');

}

}

 

this means that when someone from australia comes in, he gets english and australian dollars, Europeans get english and euro, people from hong kong get english or chinese (depending how they got in) and hong kong dollars.

 

 

In create account, just before displaying the state listbox, I use:

 

$country = tep_get_country_by_language($browser_language, true); // return the country code

 

that way, the country selected in the listbox is the most likely country of the customer and the state listbox is already filled with the states from that country.

You have to make sure that every country you support does have at least 1 state or zone.

Treasurer MFC

Posted
well, you add this function to includes/functions/general.php:

 

you give this function the language code from the browser.

it returns either the country name or the osc country code based on the $give_code parameter.

 

The latter I use set the default country for the listbox in create account and such.

Note that I only have put in the codes for the countries  I support, all others default to 206 Taiwan in my case.

function tep_get_country_by_language($country_code, $give_code = false) {

 

$code1 = substr($country_code,0,2);

$code2 = substr($country_code,3,2);

$country_name = '';

$ctry_code = '';

 

if ($code1 == "af") {$country_name = 'Afrikaans';

} elseif ($code1 == "ar") {$country_name = 'Arabic';

    if ($code2 == "ae") {$country_name = 'UAE'; $ctry_code = 221;}

    if ($code2 == "bh") {$country_name = 'Bahrain';$ctry_code = 17;}

    if ($code2 == "eg") {$country_name = 'Egypt';$ctry_code = 63;}

    if ($code2 == "dz") {$country_name = 'Algeria';}

    if ($code2 == "iq") {$country_name = 'Iraq';}

    if ($code2 == "jo") {$country_name = 'Jordan';}

    if ($code2 == "kw") {$country_name = 'Kuwait';$ctry_code = 114;}

    if ($code2 == "lb") {$country_name = 'Lebanon';}

    if ($code2 == "ly") {$country_name = 'Libya';}

    if ($code2 == "ma") {$country_name = 'Morocco';}

    if ($code2 == "om") {$country_name = 'Oman';}

    if ($code2 == "qa") {$country_name = 'Qatar';}

    if ($code2 == "sa") {$country_name = 'Saudi';$ctry_code = 184;}

    if ($code2 == "sy") {$country_name = 'Syria';}

    if ($code2 == "tn") {$country_name = 'Tunisia';}

    if ($code2 == "ye") {$country_name = 'Yemen';}

} elseif ($code1 == "be") {$country_name = 'Belarusian';

} elseif ($code1 == "bg") {$country_name = 'Bulgarian';

} elseif ($code1 == "ca") {$country_name = 'Catalan';

} elseif ($code1 == "cs") {$country_name = 'Czech';$ctry_code = 56;

} elseif ($code1 == "da") {$country_name = 'Denmark';$ctry_code = 57;

} elseif ($code1 == "de") {$country_name = 'Germany';$ctry_code = 81;

    if ($code2 == "at") {$country_name = 'Austria';$ctry_code = 14;}

    if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

    if ($code2 == "li") {$country_name = 'Liechtenstein';$ctry_code = 122;}

    if ($code2 == "lu") {$country_name = 'Luxembourg';$ctry_code = 124;}

} elseif ($code1 == "el") {$country_name = 'Greece';$ctry_code = 84;

} elseif ($code1 == "en") {$country_name = 'Other English';$ctry_code = 223;

    if ($code2 == "us") {$country_name = 'USA';$ctry_code = 223;}

    if ($code2 == "au") {$country_name = 'Australia';$ctry_code = 13;}

    if ($code2 == "bz") {$country_name = 'Belize';}

    if ($code2 == "ca") {$country_name = 'Canada';$ctry_code = 38;}

    if ($code2 == "gb") {$country_name = 'UK';$ctry_code = 222;}

    if ($code2 == "ie") {$country_name = 'Ireland';$ctry_code = 103;}

    if ($code2 == "jm") {$country_name = 'Jamaica';}

    if ($code2 == "nz") {$country_name = 'New Zealand';$ctry_code = 153;}

    if ($code2 == "tt") {$country_name = 'Trinidad';}

    if ($code2 == "za") {$country_name = 'South Africa';$ctry_code = 193;}

} elseif ($code1 == "es") {$country_name = 'Spain';$ctry_code = 195;

    if ($code2 == "ar") {$country_name = 'Argentina';$ctry_code = 10;}

    if ($code2 == "bo") {$country_name = 'Bolivia';}

    if ($code2 == "cl") {$country_name = 'Chile';}

    if ($code2 == "co") {$country_name = 'Colombia';}

    if ($code2 == "cr") {$country_name = 'Costa Rica';}

    if ($code2 == "do") {$country_name = 'Dominican';}

    if ($code2 == "ec") {$country_name = 'Ecuador';}

    if ($code2 == "gt") {$country_name = 'Guatemala';}

    if ($code2 == "hn") {$country_name = 'Honduras';}

    if ($code2 == "mx") {$country_name = 'Mexico';$ctry_code = 138;}

    if ($code2 == "ni") {$country_name = 'Nicaragua';}

    if ($code2 == "pa") {$country_name = 'Panama';}

    if ($code2 == "pe") {$country_name = 'Peru';}

    if ($code2 == "pr") {$country_name = 'Puerto Rico';}

    if ($code2 == "py") {$country_name = 'Paraguay';}

    if ($code2 == "sv") {$country_name = 'El Salvador';}

    if ($code2 == "uy") {$country_name = 'Uruguay';}

    if ($code2 == "ve") {$country_name = 'Venezuela';}

} elseif ($code1 == "et") {$country_name = 'Estonian';

} elseif ($code1 == "eu") {$country_name = 'Basque';

} elseif ($code1 == "fa") {$country_name = 'Farsi';

} elseif ($code1 == "fi") {$country_name = 'Finland';$ctry_code = 72;

} elseif ($code1 == "fo") {$country_name = 'Faeroes';

} elseif ($code1 == "fr") {$country_name = 'France';$ctry_code = 73;

    if ($code2 == "be") {$country_name = 'Belgium';$ctry_code = 21;}

    if ($code2 == "ca") {$country_name = 'Canada';$ctry_code = 38;}

    if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

    if ($code2 == "ca") {$country_name = 'Luxembourg';$ctry_code = 124;}

} elseif ($code1 == "gd") {$country_name = 'Scotland';$ctry_code = 222;

    if ($code2 == "ie") {$country_name = 'Ireland';}

} elseif ($code1 == "he") {$country_name = 'Hebrew';

} elseif ($code1 == "hi") {$country_name = 'Hindi';

} elseif ($code1 == "hr") {$country_name = 'Croatian';

} elseif ($code1 == "hu") {$country_name = 'Hungarian';$ctry_code = 97;

} elseif ($code1 == "in") {$country_name = 'Indonesian';$ctry_code = 100;

} elseif ($code1 == "is") {$country_name = 'Icelandic';$ctry_code = 98;

} elseif ($code1 == "he") {$country_name = 'Hebrew';$ctry_code = 104;

} elseif ($code1 == "it") {$country_name = 'Italy';$ctry_code = 105;

    if ($code2 == "ch") {$country_name = 'Switzerland';$ctry_code = 204;}

} elseif ($code1 == "ja") {$country_name = 'Japan';$ctry_code = 107;

} elseif ($code1 == "ji") {$country_name = 'Yiddish';$ctry_code = 104;

} elseif ($code1 == "ko") {$country_name = 'Korea';

} elseif ($code1 == "lt") {$country_name = 'Lithuania';

} elseif ($code1 == "lv") {$country_name = 'Latvian';

} elseif ($code1 == "mk") {$country_name = 'Macedonia';

} elseif ($code1 == "ms") {$country_name = 'Malaysia';$ctry_code = 129;

} elseif ($code1 == "mt") {$country_name = 'Malta';$ctry_code = 132;

} elseif ($code1 == "nl") {$country_name = 'Netherlands';$ctry_code = 150;

    if ($code2 == "be") {$country_name = 'Belgium';$ctry_code = 21;}

} elseif ($code1 == "no") {$country_name = 'Norway';$ctry_code = 160;

} elseif ($code1 == "pl") {$country_name = 'Poland';$ctry_code = 170;

} elseif ($code1 == "pt") {$country_name = 'Portugual';$ctry_code = 171;

    if ($code2 == "br") {$country_name = 'Brazil';$ctry_code = 30;}

} elseif ($code1 == "rm") {$country_name = 'Romania';

} elseif ($code1 == "ro") {$country_name = 'Romania';

} elseif ($code1 == "ru") {$country_name = 'Russia';

} elseif ($code1 == "sb") {$country_name = 'Sorbian';

} elseif ($code1 == "sk") {$country_name = 'Slovak';

} elseif ($code1 == "sl") {$country_name = 'Slovenian';

} elseif ($code1 == "sq") {$country_name = 'Albania';

} elseif ($code1 == "sr") {$country_name = 'Serbia';

} elseif ($code1 == "sv") {$country_name = 'Sweden';$ctry_code = 203;

    if ($code2 == "fi") {$country_name = 'Finland';$ctry_code = 72;}

} elseif ($code1 == "sx") {$country_name = 'Sutu';

} elseif ($code1 == "sz") {$country_name = 'Sami';

} elseif ($code1 == "tn") {$country_name = 'Tswana';

} elseif ($code1 == "tr") {$country_name = 'Turkey';

} elseif ($code1 == "ts") {$country_name = 'Tsonga';

} elseif ($code1 == "uk") {$country_name = 'Ukrainian';

} elseif ($code1 == "th") {$country_name = 'Thailand';$ctry_code = 209;

} elseif ($code1 == "ur") {$country_name = 'Urdu';

} elseif ($code1 == "ve") {$country_name = 'Venda';

} elseif ($code1 == "vi") {$country_name = 'Vietnam';

} elseif ($code1 == "xh") {$country_name = 'Xhosa';

} elseif ($code1 == "zh") {$country_name = 'China';$ctry_code = 44;

    if ($code2 == "cn") {$country_name = 'China';$ctry_code = 44;}

    if ($code2 == "hk") {$country_name = 'Hong Kong';$ctry_code = 96;}

    if ($code2 == "sg") {$country_name = 'Singapore';$ctry_code = 188;}

    if ($code2 == "tw") {$country_name = 'Taiwan';$ctry_code = 206;}

} elseif ($code1 == "zu") {$country_name = 'Zulu';}

 

// if all fails

if ($country_name == '') {$country_name = 'Taiwan';}

if ($ctry_code == '')    {$ctry_code = '206';}

 

  if ($give_code) {

    return ($ctry_code);

  } else {

    return ($country_name);

  }

}

then in application_top.php

 

after :

 

if (!tep_session_is_registered('language') || ($given_language != '')) {

  if (!tep_session_is_registered('language')) {

    tep_session_register('language');

    tep_session_register('languages_id');

  }

 

  include(DIR_WS_CLASSES . 'language.php');

you add:

 

  $given_language = $_GET['language'];

 

  if ($given_language != '') {

    $lng = new language($given_language);

    $language = $lng->language['directory'];

    $languages_id = $lng->language['id'];

  else {

      $lng->get_browser_language();

      $language = $lng->language['directory'];

      $languages_id = $lng->language['id'];

 

      // get client language setting

      $browser_language = getenv('HTTP_ACCEPT_LANGUAGE');

      $your_country = tep_get_country_by_language($browser_language, false); // return the country name

 

      if ($lng->language['directory'] == 'english') {

        // set first supported currency based on browser language setting for english & unsupported languages

        switch ($your_country) {

          case 'Japan'      : $currency = 'JPY';break;

          case 'China'      : $currency = 'CNY';break;

          case 'Hong Kong'  : $currency = 'HKD';break;

          case 'Netherlands' : $currency = 'EUR';break;

          case 'Italy'      : $currency = 'EUR';break;

          case 'Spain'      : $currency = 'EUR';break;

          case 'Belgium'    : $currency = 'EUR';break;

          case 'Austria'    : $currency = 'EUR';break;

          case 'Germany'    : $currency = 'EUR';break;

          case 'Greece'      : $currency = 'EUR';break;

          case 'Finland'    : $currency = 'EUR';break;

          case 'Sweden'      : $currency = 'EUR';break;

          case 'Norway'      : $currency = 'EUR';break;

          case 'Denmark'    : $currency = 'EUR';break;

          case 'France'      : $currency = 'EUR';break;

          case 'Australia'  : $currency = 'AUD';break;

          case 'UK'          : $currency = 'GBP';break;

          default            : $currency = 'USD';

        }

      }

 

      if ($lng->language['directory'] == 'tchinese') {

        // set first supported currency based on browser language setting for english/unsupported languages

        switch ($your_country) {

          case 'China'      : $currency = 'CNY';break;

          case 'Hong Kong'  : $currency = 'HKD';break;

          default            : $currency = 'TWD';

        }

      }

 

      if (!tep_session_is_registered('currency')) {

        tep_session_register('currency');

      }

  }

 

this means that when someone from australia comes in, he gets english and australian dollars, Europeans get english and euro, people from hong kong get english or chinese (depending how they got in) and hong kong dollars.

In create account, just before displaying the state listbox, I use:

 

      $country = tep_get_country_by_language($browser_language, true); // return the country code

 

that way, the country selected in the listbox is the most likely country of the customer and the state listbox is already filled with the states from that country.

You have to make sure that every country you support does have at least 1 state or zone.

 

 

correction on the application top part:

 

$lng = new language($given_language);

 

if ($given_language != '') {

$language = $lng->language['directory'];

$languages_id = $lng->language['id'];

} else {

$lng->get_browser_language();

$language = $lng->language['directory'];

$languages_id = $lng->language['id'];

 

$your_country = tep_get_country_by_language($browser_language, false);

 

if ($lng->language['directory'] == 'english') {

// set first currency based on browser language setting for english unsupported languages

switch ($your_country) {

case 'Japan' : $currency = 'JPY';break;

case 'China' : $currency = 'CNY';break;

case 'Hong Kong' : $currency = 'HKD';break;

case 'Netherlands' : $currency = 'EUR';break;

case 'Italy' : $currency = 'EUR';break;

case 'Spain' : $currency = 'EUR';break;

case 'Belgium' : $currency = 'EUR';break;

case 'Austria' : $currency = 'EUR';break;

case 'Germany' : $currency = 'EUR';break;

case 'Greece' : $currency = 'EUR';break;

case 'Finland' : $currency = 'EUR';break;

case 'Sweden' : $currency = 'EUR';break;

case 'Norway' : $currency = 'EUR';break;

case 'Denmark' : $currency = 'EUR';break;

case 'France' : $currency = 'EUR';break;

case 'Australia' : $currency = 'AUD';break;

case 'UK' : $currency = 'GBP';break;

default : $currency = 'USD';

}

}

 

if ($lng->language['directory'] == 'tchinese') {

// set first currency based on browser language setting for english unsupported languages

switch ($your_country) {

case 'China' : $currency = 'CNY';break;

case 'Hong Kong' : $currency = 'HKD';break;

default : $currency = 'TWD';

}

}

 

if (!tep_session_is_registered('currency')) {

tep_session_register('currency');

}

}

Treasurer MFC

Archived

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

×
×
  • Create New...