簡體   English   中英

Magento貨幣轉換器

[英]Magento currency Converter

我正在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后端設置貨幣和匯率,並且實現相同,但錯誤仍然相同。

Magento僅對“基礎貨幣=>顯示貨幣”對具有費率。

您有基礎貨幣“ INR”,並且可能有“ INR => CAD”對的匯率。 您的錯誤提示您的代碼嘗試獲取“ CAD”貨幣的匯率,而在您的系統中,您尚未獲得“ CAD => INR”的匯率。

請確保您嘗試將基本貨幣的價格轉換為任何其他貨幣,而不是在兩種顯示貨幣之間轉換。 但是,如果需要此功能,則應使用自己的轉換函數,該函數可計算必要的速率。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM