Php Magento货币转换器
我正在magento的产品列表页面上实现按价格范围自定义筛选功能 我有多个货币库,基础货币是印度卢比,还有其他6到7种货币 我从价格范围中获取输入,并在产品收集中使用以下过滤器Php Magento货币转换器,php,magento,Php,Magento,我正在magento的产品列表页面上实现按价格范围自定义筛选功能 我有多个货币库,基础货币是印度卢比,还有其他6到7种货币 我从价格范围中获取输入,并在产品收集中使用以下过滤器 $this->_productCollection = $layer->getProductCollection(); if($this->getRequest()->getParam('filterPrice')){ $baseCurrency = Ma
$this->_productCollection = $layer->getProductCollection();
if($this->getRequest()->getParam('filterPrice')){
$baseCurrency = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrency = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = explode('-',$this->getRequest()->getParam('filterPrice'));
$min = str_replace(Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(),'',$price[0]);
$min = $this->currencyConverter($min, $currentCurrency, $baseCurrency);
$max = str_replace(Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(),'',$price[1]);
$max = $this->currencyConverter($max, $currentCurrency, $baseCurrency);
$this->_productCollection->addAttributeToFilter('price',array('from'=>$min,'to'=>$max));
}
其中currencyConverter函数类似于
public function currencyConverter($amount,$from,$to)
{
if($from!=$to){
$targetCurrency = Mage::getModel('directory/currency')->load($to);
$price = Mage::helper('directory')->currencyConvert($amount, $from, $targetCurrency);
$converted_final_price = Mage::app()->getStore()->roundPrice($price);
return $converted_final_price;
}else{
return $amount;
}
}
但我有以下错误
来自“CAD-INR”的未定义比率。
从其他线程中,我知道我需要从magento后端设置货币和汇率,我实现了相同的设置,但错误仍然保持不变。magento仅对“基本货币=>显示货币”对进行汇率设置 您有基础货币“INR”,并且您可能有对“INR=>CAD”的汇率。 您的错误表示您的代码试图获取“CAD”货币的汇率,而在您的系统中,您没有“CAD=>INR”的汇率 请确保您尝试将基础货币的价格转换为任何其他货币,而不是两种显示货币之间的价格。
但是如果您需要这个,您应该使用您自己的转换函数来计算必要的利率。是的,这是正确的,我尝试过这个,为我工作过,但是在magento上没有关于这个的适当文档