0

I use Magento ver. 1.8.1.0 and when I go one my website I've got this error:

Fatal error: Call to a member function getCode() on a non-object in app/code/core/Mage/Directory/Model/Currency.php on line 193

When I choose USD for currency in Configuration -> Currency setting, it's ok, but after, with my payment method it doesn't work because it need CHF (Swiss franc) so if I choose CHF for Currency I have the Fatal error for all the website...

On line 194 I have this function:

public function convert($price, $toCurrency = null)
{
    if (is_null($toCurrency)) {
        return $price;
    } else {
        $rate = $this->getRate($toCurrency);
        if ($rate) {
            return $price * $rate;
        }
    }

    throw new Exception(Mage::helper('directory')->__('Undefined rate from "%s-%s".', $this->getCode(),$toCurrency->getCode()));
}

and the getCode() function:

/**
 * Get currency code
 *
 * @return string
 */
public function getCode()
{
    return $this->_getData('currency_code');
}

I don't know what is wrong, somebody can help me? Thank you

1 Answer 1

1

I think the currency is missing in the directory_currency_rate table.

Check the table for your currency. If it is missing, you have two options to solve it.

  1. Enable the cronjob to retrieve the currency from the webservice in configuration.
  2. Go to "System > Manage Currency > Rates and click the import button

You should clear the cache and delete all your cookies (to get rid of your session and shopping cart) afterwards and test again.

3
  • Thank you for your answer but: 0. In the directory_currency_rate table I didn't have the CHF entry, so I put one. I change the currency in Configuration -> Currency setting. Clean cache - cookies => nothing change. 1. How do you enable cronjob? 2. I import rates but nothing change too
    – Jimix
    Oct 31, 2014 at 15:52
  • 1: Did you clear the Magento cache our only your browsercache? 2: What's in the directory_currency_rate table now? 3: Please check the currency settings in your configuration ("System" > "Configuration" > "Currency Setup". That's also where you can enable the cronjob.
    – RobM84
    Oct 31, 2014 at 16:54
  • I forgot to put CHF to USD and USD to CHF in my directory_currency_rate! Thank you for your help RobM
    – Jimix
    Nov 3, 2014 at 7:28

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.