magento-将订单金额从当前货币转换为基础货币 [英] magento - convert order amount from current currency to base currency
问题描述
我正在尝试将订单金额从当前货币转换为基础货币,下面是我尝试过的代码,但没有成功.
I am trying to convert order amount from current currency to base currency, below is the code which i tried, but no go.
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = 1;
$priceTwo = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode);
推荐答案
无法使用Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode)
方法将价格从当前货币转换为基础货币,因为Magento找不到带有"currentCurrency" =>的行 directory_currency_rate 表中的"baseCurrency"关系.
It is not possible to convert a price from current currency to base currency using Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode)
method because Magento doesn't find the row with "currentCurrency"=>"baseCurrency" relation in the directory_currency_rate table.
要解决此问题,您只需将价格除以"baseCurrency" =>"currentCurrency"费率即可.
To solve this issue you can simply do a division of the price by "baseCurrency"=>"currentCurrency" rate.
如何获得"baseCurrency" =>"currentCurrency"汇率并解决您的问题? 通过这种方式:
How could you get "baseCurrency"=>"currentCurrency" rate and solve your issue? In this way:
// the price
$price=1;
// Base Currency
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
// Current Currency
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
// Allowed currencies
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));
// the price converted
$price=$price/$rates[$currentCurrencyCode];
这篇关于magento-将订单金额从当前货币转换为基础货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!