$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to); 
    echo $newPrice;

I use this code but it not work for me it gives error

Fatal error: Call to a member function getCode() on string in /home4/proddev/public_html/app/code/core/Mage/Directory/Model/Currency.php on line 194


Look at the function currentConvert() the price should be an float

replace $price=10; with $price=10.00;

 * Convert currency
 * @param float $amount
 * @param string $from
 * @param string $to
 * @return float
public function currencyConvert($amount, $from, $to = null)
        if (empty($this->_currencyCache[$from])) {
            $this->_currencyCache[$from] = Mage::getModel('directory/currency')->load($from);
        if (is_null($to)) {
            $to = Mage::app()->getStore()->getCurrentCurrencyCode();
        $converted = $this->_currencyCache[$from]->convert($amount, $to);
        return $converted;


Go to System>Configuration>Currency Setup and make sure the currencies you are using are selected in the Allowed Currencies setting.

Nb: Your error means that the convert method cannot find a rate !

  • still not work for me Nov 16 '17 at 11:47
  • look my updated answer @jigs parmar
    – PЯINCƎ
    Nov 16 '17 at 12:07
  • yes it is allowed Nov 17 '17 at 3:43

Make sure which is your base currency and to which currency you want to convert

Try this

$from = 'USD';
$to = 'HKD';
$price = 10;
$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);
echo $newPrice;

Make sure you have allowed the currency from System > Configuration > Currency Setup and you have defined the currency rate in System > Manage Currency > Rates.

  • From USD to HKD is work but HKD to USD not work Nov 17 '17 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.