我正在尝试使用以下代码在单独的文件中转换Magento 1.5中的货币以检查货币转换。我在管理员中有两家商店以及各自的货币设置。

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 ));

我会遇到以下错误,

致命错误:在/var/www/vhosts/www.test.com/httpdocs/app/code/code/code/core/mmage/mmage/model/model/model/model/currency.php上,在in/var/www/vhosts/www.test.com/httpdocs.php上拨打成员函数getCode()

我尝试关注这个 http://www.magentocommerce.com/boards/v/viewthread/118631/p15/#t381027, ,但它行不通。这里怎么了?

有帮助吗?

解决方案

PHP致命错误是源于转换方法中的一个错误,该错误假设$ tocrentency是对象。但是,当试图施加异常时,正在造成错误:

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

此错误的含义是 convert 方法找不到费率。我测试了您的代码,并且只要您要转换为/转换的货币的费率就可以正常工作。

您需要做的是导航到系统 - >配置 - >货币设置,并确保在允许的货币设置中选择所使用的货币。

选择允许的货币后,您需要设置费率。您可以通过进入系统 - >管理货币利率来做到这一点。从那里,您可以将自己的转换率输入到网格中,也可以单击“导入”按钮,然后单击“保存货币率”。

一旦您拥有转换设置的货币率,它就应该无需挂断。

其他提示

尝试以下代码将有效

$_Baseprice = $_product->getPrice(); 
    $_Currentcurrencycode =Mage::app()->getStore()->getCurrentCurrencyCode();
    //This will return USD, EUR e.t.c
    //echo $_Currentcurrencycode;
    if ($_Currentcurrencycode == 'USD') {$_convertedCurrency = Mage::helper('directory')->currencyConvert($cprice, 'SAR', 'USD');}
    else {$_convertedCurrency = Mage::helper('directory')->currencyConvert($cprice, 'SAR', 'SAR');}
    //_convertedCurrency will return price without symbol
    //echo $_convertedCurrency ;
许可以下: CC-BY-SA归因
scroll top