【问题标题】:Magento currency ConverterMagento 货币转换器
【发布时间】:2014-08-11 06:48:36
【问题描述】:

我正在 magento 的产品列表页面上按价格范围功能实现自定义过滤器

我有多种货币商店,基础货币是 INR ,其他 6 到 7 种货币

我从价格范围中获取输入并在产品集合中使用以下过滤器

$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 后端设置货币和汇率,并且我实现了相同的,但错误仍然相同。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    Magento 仅对“基础货币 => 显示货币”对有汇率。

    您拥有基础货币“INR”,并且您可能拥有货币对“INR => CAD”的汇率。 您的错误表明您的代码尝试获取“CAD”货币的汇率,而在您的系统中您没有为“CAD => INR”评分。

    请确保您尝试将基础货币的价格转换为任何其他货币,而不是在两种显示货币之间。 但是如果你需要这个,你应该使用你自己的转换函数来计算必要的利率。

    【讨论】:

    • 是的,这是正确的,我试过了,对我有用,但是在 magento 上没有适当的文档
    猜你喜欢
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    相关资源
    最近更新 更多