Zend Framework

Zend_Currency::toCurrency() ignores option param "currency"

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Currency
  • Labels:
    None

Description

I always use an instance of Zend_Currency to display prices etc. Now I ran into a bug after upgrading from 1.7.8 to 1.9.2 - the toCurrency method ignores the currency value in the option array. Here is a small test I used:

$value = '';
$currencyObject = new Zend_Currency('de_DE');
$value = $currencyObject->toCurrency(2.3, array('currency' => 'USD', 'precision' => 4));
Zend_Debug::dump($value); // prints "2,3000 €" - expected "2,3000 $"

$value = '';
$currencyObject = new Zend_Currency('USD', 'de_DE');
$value = $currencyObject->toCurrency(2.3, array('precision' => 4));
Zend_Debug::dump($value); // prints "2,3000 $" as expected

The first example is often used, because I cannot know which currency should be used for the customer - so setting the currency while converting is a must have for me. If I see it right, the bug depends on getSymbol() which results in an error if no locale is given. I will add a patch which corrects the problem for me.

  1. CurrencyTest.php.patch
    22/Sep/09 6:27 AM
    0.7 kB
    Dennis Becker
  2. Zend_Currency.patch
    17/Sep/09 2:49 AM
    1 kB
    Dennis Becker

Activity

Hide
Dennis Becker added a comment -

I will add additionally a Unit-Test patch ( I read the "Bughunt day" notification today) so that it does not need to be double-researched. This will take some minutes I think Just wait until I have uploaded it.

Show
Dennis Becker added a comment - I will add additionally a Unit-Test patch ( I read the "Bughunt day" notification today) so that it does not need to be double-researched. This will take some minutes I think Just wait until I have uploaded it.
Hide
Dennis Becker added a comment -

Added UnitTest to CurrencyTest.php

Show
Dennis Becker added a comment - Added UnitTest to CurrencyTest.php
Hide
Thomas Weidner added a comment -

Note that this "patch" introduces a new problem and can not be used as is.

Show
Thomas Weidner added a comment - Note that this "patch" introduces a new problem and can not be used as is.
Hide
Thomas Weidner added a comment -

Note that your provided example set's another display type at initiation than at output. This leads to the behaviour that the output uses another display that the one you set. If you would set the wished display type then the code would work. This has not changed since ZF 1.7.8.

Fixed with a new feature to automatically detect the wished display type. (r18432)

Show
Thomas Weidner added a comment - Note that your provided example set's another display type at initiation than at output. This leads to the behaviour that the output uses another display that the one you set. If you would set the wished display type then the code would work. This has not changed since ZF 1.7.8. Fixed with a new feature to automatically detect the wished display type. (r18432)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: