Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Keep chosen currency


bluevogue

Recommended Posts

I have 4 currencies in the store, but I guess it doesn't matter how many in this case.

 

The thing is that I have one currency set as default as this is the currency I purchase everything in and it is easy to calculate what I want in profit. However normally will never have anyone buying in this currency and really don't want it to show or at least not be the default currency in the list.

 

Also, if I set the "switch to default language currency" and I only have english in the store... If a customer changes to AUD and then clicks a link it pops back to USD again. Customer changes back to AUD and then clicks another link and whe're back at USD again..

 

Can someone please tell me how to keep the chosen currency and maybe at the same time not show the "default currency" ..

 

Any suggestions are appreciated.

Link to comment
Share on other sites

As I mentioned, I have this set to the currency I purchase everything in, this is because it is easy to calculate the profit margin this way.

 

Then I have EUR, USD, AUD, and SEK. I rather have one of these as default but then I will have to change the price to keep the same profit margin when the currency changes. By having my purchase currency as the default I know I will always have the same profit.

 

The annoying thing is that if I set "switch to default language currency" it will always revert to USD even if I have chosen EUR after I click a new link/change page

 

Thanks

Link to comment
Share on other sites

Rob, i am only running 1 currancy but i would expext if u change it should recalculate it for u. I am not a pro so i will stop here. If i do find anything i will be shure to let u know. and i will monitor this thread for my own knoweldge.

Sorry i can't help.

Link to comment
Share on other sites

Well the currency is changing correctly when I choose another one.

 

What I mean is that if I choose to see the prices in AUD from the currency box, later when I click a product it reverts back to USD. I want the customers chosen currency to stay as long as he is in the shop so he/she doesn't have to change to his/her prefered currency for every new page.

 

I think this can be done with a code change or maybe by implementing a cookie, but I don't know how to do this.

 

Or maybe even more simple... Can I hide the default currency from the currency box?

 

Thanks

Link to comment
Share on other sites

Well the currency is changing correctly when I choose another one.

 

What I mean is that if I choose to see the prices in AUD from the currency box, later when I click a product it reverts back to USD. I want the customers chosen currency to stay as long as he is in the shop so he/she doesn't have to change to his/her prefered currency for every new page.

 

I think this can be done with a code change or maybe by implementing a cookie, but I don't know how to do this.

 

Or maybe even more simple... Can I hide the default currency from the currency box?

 

Thanks

 

well, if you enable "switch to default", every time, the currency is set to the default currency defined for the selected language in your language file.

So turn that off and the selected currency is retained (if your sessions work properly that is.)

 

this is the code for the currency in application top:

 

// currency

if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {

if (!tep_session_is_registered('currency')) tep_session_register('currency');

 

if (isset($HTTP_GET_VARS['currency'])) {

if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;

} else {

$currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;

}

}

Treasurer MFC

Link to comment
Share on other sites

OK, so I want to turn off "switch to default" but can I hide one currency or how would go on to make the "default" currency something else than what I have set in the currency section in admin?

 

Say I have Sing$ as default currency in admin, but as I don't have any customers buying in that currency I really don't want it to show up or at least not be the default currency for the customer.

Link to comment
Share on other sites

OK, so I want to turn off "switch to default" but can I hide one currency or how would go on to make the "default" currency something else than what I have set in the currency section in admin?

 

Say I have Sing$ as default currency in admin, but as I don't have any customers buying in that currency I really don't want it to show up or at least not be the default currency for the customer.

 

not totally sure about this but you could try to look in your english.php file and set this:

 

define('LANGUAGE_CURRENCY', 'USD');

 

to the default currency you want for that language.

Treasurer MFC

Link to comment
Share on other sites

But this is used when "switch to default currency" is chosen and I do not want to use "switch to default currency" because I only have english on the site and if I have european customers they want to see the price in EUR, but as they click the next product it reverts back to USD. And of course the other way around. If I set this to EUR and I have customers from US they want to see the price in USD but have to keep choosing USD after every new product the click.

 

I still want customers to be able to choose their prefered currency but either I want to hide the currency I have as default in admin or at least make the first choice in the dropdown list to be something else than the base currency in admin.

 

Even if I have to manually hardcode it somewhere so that USD is the default in the dropdown list for currencies I would do it, instead of having Sing$ as default.

Link to comment
Share on other sites

But this is used when "switch to default currency" is chosen and I do not want to use "switch to default currency" because I only have english on the site and if I have european customers they want to see the price in EUR, but as they click the next product it reverts back to USD. And of course the other way around. If I set this to EUR and I have customers from US they want to see the price in USD but have to keep choosing USD after every new product the click.

 

I still want customers to be able to choose their prefered currency but either I want to hide the currency I have as default in admin or at least make the first choice in the dropdown list to be something else than the base currency in admin.

 

Even if I have to manually hardcode it somewhere so that USD is the default in the dropdown list for currencies I would do it, instead of having Sing$ as default.

 

well, personally I set the default currency based on the browser language setting.

 

So if a customer has french set as their browser language, they get English as language (I only have english and chinese) but euro's as currency, until they choose another one.

For us customers, they get english and USD, taiwanese get traditional chinese and TWD, japanese get english and Yen's. In the event the client has no language setting set in their browser, they get the default language and currency.

 

I believe I have put the code for that in the tips and tricks section months ago but am very happy to post it again if you cannot find it.

Treasurer MFC

Link to comment
Share on other sites

Maybe I misunderstood you..

 

Sure this is what I want, if a Swedish customer is looking thru the page currency is supposed to be SEK, if a Australian customer comes it should be AUD (or ok USD).

 

But when I tried to set the "switch to default" and I had a swedish customer they got USD and when changing to SEK it works until they click the next product and then currency reverts back to USD. I guess this is because I don't have swedish pages.

 

If you have piece of code that can sort this out it would be very much appreciated.

 

I have tried the search but to no avail (doesn't work that good..)

 

Thanks

Link to comment
Share on other sites

Maybe I misunderstood you..

 

Sure this is what I want, if a Swedish customer is looking thru the page currency is supposed to be SEK, if a Australian customer comes it should be AUD (or ok USD).

 

But when I tried to set the "switch to default" and I had a swedish customer they got USD and when changing to SEK it works until they click the next product and then currency reverts back to USD. I guess this is because I don't have swedish pages.

 

If you have piece of code that can sort this out it would be very much appreciated.

 

I have tried the search but to no avail (doesn't work that good..)

 

Thanks

 

 

this goes into application_top right after this function which tries to determine the language based on the browser settings :

 

so after this:

 

$lng->get_browser_language();

 

you add this code which determines the country based on the language settings and sets the currency accordingly.

 

// get client language setting

$browser_language = getenv('HTTP_ACCEPT_LANGUAGE');

// false gives country name, true gives osc country code

$your_country = tep_get_country_by_language($browser_language, false);

switch ($your_country) {

case 'Taiwan' : $currency = 'TWD';break;

case 'USA' : $currency = 'USD';break;

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

case 'UK' : $currency = 'GBP';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;

default : $currency = 'USD';

}

if (!tep_session_is_registered('currency')) {

tep_session_register('currency');

}

 

 

 

this is the function to go in general.php. I also use this function to set the default country for create account and order_info but there call it with the value "true" to get the country code instead of the name.

 

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

}

}

Treasurer MFC

Link to comment
Share on other sites

Thanks!

 

I will try it out!!

 

you can test it, just go to my site which is listed in my profile and simply change your browser language settings. I only have 2 languages but at least 5 currencies.

 

There may be a little difference as I also set the selected currency and language in a cookie so that if the user changes either, it is recorded in the cookie and subsequently the user will get that in the future until changed again.

Treasurer MFC

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...