Issues

ZF-10169: Zend_Currency::getCurrencyList( $myRegion ) returns all currencies and all regions, not the currencies for the regions specified.

Issue Type:

Bug

Created:

2010-07-16T10:35:52.000+0000

Last Updated:

2010-07-28T00:29:23.000+0000

Status:

Resolved

Fix version(s):

1.11.0 (02/Nov/10)

Reporter:

marc wren (marcwren)

Assignee:

Thomas Weidner (thomas)

Tags:

Zend_Currency

Zend_Locale

Related issues:

Attachments:

Description

According to the documentation for Zend_Currency:
getCurrencyList(): Returns a list of all currencies which are used in the given region as array. Defaults to the objects locale when no region has been given.

Given this description, I would expect the code snippet "$oCurrency = new Zend_Currency(); $aAvailableCurrencies = $oCurrency->getCurrencyList();" to return a list of currencies used in the region specified by the user's browser. However, this code is instead returning the list of all currencies and the regions associated with each currency.

Looking at the Zend_Currency::getCurrencyList() method, either the line "Zend_Locale_Data::getList('', 'regiontocurrency', $region);" is not returning the expected data or additional processing must be done before returning a value.

Comments

Posted by Thomas Weidner (thomas) on 2010-07-16T15:17:43.000+0000

You are missing one thing.

To which locale has Zend_Currency been set?
This information in not available by the snippet you gave.

It can be the users locale, the environment locale, a registry locale or a locale which is set within the bootstrap.

Additionally, when you've set only a language without a region this method is unable to return proper data because when no region is given, region specific informations can not be retrieved.

The main question which only you can answer is: Which region is requested by Zend_Currency within the subcall.

Posted by marc wren (marcwren) on 2010-07-19T09:04:28.000+0000

I reproduced this issue for the regions US and FR. I tested a few different ways:

I Initialize the Zend_Locale object by detecting the user's region from their browser settings. I tested with my browser's language preference to "fr-FR" and again with it set to "en-US" using the following code:
Zend_Registry::set( 'Zend_Locale', new Zend_Locale() );
// Later in my code, I allowed Zend_Currency to pull the Zend_Locale I had set in the registry as follows:
$oCurrency = new Zend_Currency();
$aAvailableCurrencies = $oCurrency->getCurrencyList();

I also tried using the ZFDEFAULT region but this is set to "en" and so results in an exception saying that the region could not be deteremined:
Zend_Registry::set( 'Zend_Locale', new Zend_Locale( Zend_Locale::ZFDEFAULT ) );

I also tried passing the expected region directly to the Zend_Currency component. For both "en_US" and "fr_FR" I did the following:
$oCurrency = new Zend_Currency( "en_US" );
$aAvailableCurrencies = $oCurrency->getCurrencyList();

Lastly, I tried passing the expected region directly to the getCurrencyList method for both FR and US:
$oCurrency = new Zend_Currency();
$aAvailableCurrencies = $oCurrency->getCurrencyList( "US" );

Digging a little deeper into the Zend_Locale_Data::getList() method, I'm seeing the following strings generated as the $id value being loaded from cache (line 316 in Zend_Locale_Data for framework version 1.10.6):
"Zend_LocaleL_fr_FR_regiontocurrency_FR" (browser set to fr_FR and Zend_Currency initialized to fr_FR)
"Zend_LocaleL_fr_FR_regiontocurrency_US" (browser set to fr_FR and Zend_Currency initialized to en_US)
"Zend_LocaleL_en_regiontocurrency_US" (browser language not specified and Zend_Currency initialized to en_US)
"Zend_LocaleL_en_regiontocurrency_FR" (browser language not specified and Zend_Currency initialized to fr_FR)

However, all of these cache indexes return the exact same array of 167 currency => region pairs. I'm assuming that the expected result from the above cache requests should be an array of currency names associated with the region specified at the end of the cache index string.