I am trying to convert currency in Magento 1.5 using the following code in a separate file to check currency conversion. I have two stores with respective currency settings in the admin.
set_time_limit(0);
error_reporting(1);
ini_set('display_errors', 1);
define('D_S', DIRECTORY_SEPARATOR);
require_once 'app/Mage.php';
umask(0);
Mage::app();
$_fromCurr = 'USD';
if( Mage::app()->getStore()->getCurrentCurrencyCode() == 'CAD') {
$_locale = 'en_CA';
$_toCurr = 'CAD';
} else {
$_locale = 'en_US';
$_toCurr = 'USD';
}
$currency = new Zend_Currency($_locale);
$amount = 150;
echo $_price = $currency->toCurrency(round( Mage::helper('directory')->currencyConvert( $amount, $_fromCurr, $_toCurr ), 2 ));
I am getting following error,
Fatal error: Call to a member function getCode() on a non-object in /var/www/vhosts/www.test.com/httpdocs/app/code/core/Mage/Directory/Model/Currency.php on line 171
I tried following this http://www.magentocommerce.com/boards/v/viewthread/118631/P15/#t381027, but it does not work. What is wrong here?
round( Mage::helper('directory')->currencyConvert( $amount, $_fromCurr, $_toCurr ), 2 )