Zen Cart Logo
Forums / Bug Reports / [Done v1.3.8] bug in use_default_language_currency switch

[Done v1.3.8] bug in use_default_language_currency switch

Locked

Views: 4,131

Results 1 to 20 of 20
This thread is locked. New replies are disabled.
15 Apr 2007, 6:21 AM
#1
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

[Done v1.3.8] bug in use_default_language_currency switch

I am selling exclusively to other countries. It would be nice if I could price my products in my local currency (Taiwan dollars) and allow my customers to select their own currency.

Problem #1: I don't want TWD to show up as the default currency. USD would be OK, and I can do this by setting 'Switch to Default Language Currency' to TRUE and then set USD as the language currency in the english.php file. Great! But there is a lingering problem:

Problem #2: If the customer changes the currency to (say) UK pounds, the currency keeps on switching back to US dollars with each new page view.

So my question:

Is there any way to use US dollars as the default display currency that shows when first arriving at the site, use TWD as the default pricing currency, and allow customer to switch to their preferred currency and maintain that switch for the duration of their session?

15 Apr 2007, 12:38 PM
#2
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

I don't mind talking to myself because it helps to clarify the problems when I write them out.

I *can't *use 'Switch to Default Language Currency' - so that has to be set to off...

Now I just need a way to insert a SELECTED tag in the currency drop-down box.

The tpl_currencies.php file holds the drop-down box, so I'm thinking I need to have an extra row in the database for the SELECTED tag, or simply hard-code the *tpl_currencies.php *file for my selected currencies.

Maybe that's the easiest way...

15 Apr 2007, 6:02 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

paul3648:

Problem #2: If the customer changes the currency to (say) UK pounds, the currency keeps on switching back to US dollars with each new page view.This is not normal behaviour, and fixing this problem should be the solution for your needs.

What version of Zen Cart are you using?
What addons/mods have you installed?
What version of PHP and MySQL are you using?

16 Apr 2007, 8:43 AM
#4
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

DrByte:

This is not normal behaviour, and fixing this problem should be the solution for your needs.

What version of Zen Cart are you using?
What addons/mods have you installed?
What version of PHP and MySQL are you using?

My test site has:

ZC 1.37
PHP 5.2.0
MySQL 4.1.21-standard

Addons include Testimonials, Google Froogle, Japanese Language (just the front end), css horizontal menu, css flyout categories, internet explorer stylesheet overrides, and PPEC-137-patches-March21-2007.

Since it's a test site I can fool around with the various files.

Thanks for this clue. I'll report back anything I find...

16 Apr 2007, 3:11 PM
#5
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

DrByte:

This is not normal behaviour, and fixing this problem should be the solution for your needs.

So you are saying that any changes to the currency should stick for the duration of the session?

Where is that info stored?

I've tried changing the various settings under 'configuration/sessions' with no luck.

16 Apr 2007, 4:03 PM
#6
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

I've just tested this on another installation and get the same behaviour:

When 'Switch to Default Language Currency' is set to true, each new page refresh bring back the default currency for that language.

So if English is set to USD, the customer switches to British pounds, the next page the currency is back to USD.

That makes this setting ('Switch to Default Language Currency') almost useless, considering the large number of countries that use English but don't use the USD, or an English-speaking person living in a country which uses another currency than USD.

18 Apr 2007, 1:36 AM
#7
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

I've also tested this on a new installation with both php 5 and php 4, so I understand this, venerable zen masters, as a test of my worthiness :eek:

init_currencies.php is the key - right? It seems to me there should be a flag that is set when changing currencies during a session, so the code would be something like:

if flag == true
don't do anything
else
init_currencies.php stuff

Just wish I had the programming skills to make it a reality :(

24 Apr 2007, 8:45 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

Does this help?

Try replacing your /includes/init_includes/init-currencies.php file contents with this:```

<?php /** * initialise currencies * * @package initSystem * @copyright Copyright 2003-2007 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: init_currencies.php 6244 2007-04-21 07:53:26Z drbyte $ */ if (!defined('IS_ADMIN_FLAG')) { die('Illegal Access'); } $new_currency = (isset($_GET['currency'])) ? zen_currency_exists($_GET['currency']) : zen_currency_exists($_SESSION['currency']); if ($new_currency == false || isset($_GET['language'])) $new_currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? zen_currency_exists(LANGUAGE_CURRENCY) : $new_currency; if ($new_currency == false) $new_currency = zen_currency_exists(DEFAULT_CURRENCY, true); if ((!isset($_SESSION['currency']) && !isset($_GET['currency']) ) || (isset($_GET['currency'])) || (isset($_GET['language']) && USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && LANGUAGE_CURRENCY != $_SESSION['currency'] )) { $_SESSION['currency'] = $new_currency; } ?>
27 Apr 2007, 4:08 AM
#9
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

Thank you VERY MUCH!!

That seems to work GREAT!

:clap:

27 Apr 2007, 6:23 AM
#10
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

Sorry...I don't know why it seemed to work the first time but I'm still having problems.

This line of code:

if ($new_currency == false || isset($_GET['language'])) $new_currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? zen_currency_exists(LANGUAGE_CURRENCY) : $new_currency;
```...causes the currency to immediately revert to the default language currency if a currency change is attempted. 

If I comment out this line, the currency changes will stick throughout the session, which is OK, but ideally I would like the language currency to be chosen when first selecting a new language, and then allowing the currency to be changed from the default.

It seems to be that this can be done with an **else** statement. I've played around with it a bit but haven't found the solution yet.

All of this is with **Switch To Default Language Currency **set to true.
27 Apr 2007, 6:45 AM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

What is the URL where we can see this (with the changes I posted earlier already installed)?

27 Apr 2007, 8:28 AM
#12
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

I just sent you a pm.

27 Apr 2007, 9:03 AM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

I can't see a problem with it.

I arrive in english and USD. That's great.
I switch to japanese and it goes to TWD
I click on a product, and see products as TWD
I change to USD, and see products as USD (still in japanese)
I change to EUR, and see products as EUR (still in japanese)
I change to TWD and see products as TWD (in japanese)
I change to english and price changes to USD
I click on product listing to be sure - yes, in USD
I change to AUD, and see prices in AUD, and english
I change to EUR, and see prices in EUR, english.
Back to japanese in TWD
Click on a product to be sure -- yes, TWD
Change to CAD -- product price changes to CAD, in japanese

Looks good.

27 Apr 2007, 9:34 AM
#14
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

That's the way it seemed to work when I first installed your new file. But for me now, (still and I just checked in IE whereas before I was just using Firefox) I'm getting very strange results.

I've just noticed, though, if I change the currency it shows in the address bar

http://MY_SITE.com/index.php?currency=GBP&main_page=index&cPath=1&sort=20a&language=jp

...even when the display currency is still yen.

If I move to the next product, though, and switch the currency again, THIS time it will stick.

But if I change back to English, the weirdness starts all over...

27 Apr 2007, 9:51 AM
#15
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

I just tried it again after clearing my cache and it works well at the beginning. After switching the language and/or currency a few times things start to get weird.

27 Apr 2007, 10:10 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

Correct -- if you change the language or currency, you need to click another link besides the language or currency option before changing those again.

27 Apr 2007, 10:49 AM
#17
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

OK I see - the way you explain it - it works great.

But if someone arrives at the site and want to switch to Japanese and British pounds they might get confused...

So that brings me to a related issue - the "language selector" - when set to 'Browser" does not seem to work. If I set my language in Firefox to Japanese, I still arrive at my English version. I know the language selector is working in FF because if I go to Google I get the Japanese version.

This should go to another thread, right?

27 Apr 2007, 11:05 AM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

paul3648:

OK I see - the way you explain it - it works great.

But if someone arrives at the site and want to switch to Japanese and British pounds they might get confused...Will work on a solution for this.

So that brings me to a related issue - the "language selector" - when set to 'Browser" does not seem to work. If I set my language in Firefox to Japanese, I still arrive at my English version. I know the language selector is working in FF because if I go to Google I get the Japanese version.

This should go to another thread, right?

However, I believe "ja" is the correct language code for japanese, not "jp".
Thus, renaming your language code to "ja" instead of "jp" in your Zen Cart Admin should fix this.
If not, another thread would be suitable for this issue.
Post it in this Bug Reports section so it can be reviewed.

27 Apr 2007, 11:29 AM
#19
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.8] bug in use_default_language_currency switch

paul3648:

But if someone arrives at the site and want to switch to Japanese and British pounds they might get confused...Try this edit:
near the end of the code I gave you earlier, find this line:$_SESSION['currency'] = $new_currency;add this on a new line immediately after it:```
if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));

28 Apr 2007, 1:50 AM
#20
paul3648 avatar

paul3648

Zen Follower

Join Date:
Mar 2007
Location:
Taiwan
Posts:
239
Plugin Contributions:
0

Re: [Done v1.3.8] bug in use_default_language_currency switch

DrByte:

Try this edit:

That works perfectly. Thank you SO much!

As for the language setting to the browser default, I tried it with french and it seems to work correctly. Just for some reason Japanese is not loaded automatically. I changed the setting to ja like you suggested and it didn't make a difference. For testing I installed French, Chinese, and Japanese, set my browser languages to 1. Japanese, 2 Chinese, 3 French, 4 English.

It skipped over Japanese and Chinese and loaded in the french version. I will look at the language files to see if I can find out why.

Thanks again for this wonderful patch.