dsdeeaquu38538545 2015-10-06 06:01 采纳率: 100%
浏览 48

以编程方式在Magento中导入货币汇率

I am using Magento 1.9.1.0.

I want to import all my currency rates programmatically and i want to add x% extra to all available currencies.

// Code for Import Currency Rates
$currencyModel = Mage::getModel('directory/currency');
$currencies = $currencyModel->getConfigAllowCurrencies();
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$defaultCurrencies = $currencyModel->getConfigBaseCurrencies();
$rates=$currencyModel->getCurrencyRates($defaultCurrencies, $currencies);
$percentage = 1.05;  // x% percentage (Example 5%)
foreach($rates[$baseCurrencyCode] as $CurrencyCode => $value  ) {
    $newValue = $value*$percentage;
    $newValue = round($newValue,4);
    $currencies = array($baseCurrencyCode => array($CurrencyCode => $newValue) );
    Mage::getModel('directory/currency')->saveRates($currencies);  // Update value in DB
}

How to Import Currency Rates from Webservicex ?

If i can place this code before the above line of code thats it my goal.

Any ideas ?

  • 写回答

1条回答 默认 最新

  • duanrenzou1619 2016-06-09 10:11
    关注

    Im am using floatrates.com to get the exchange rates from Euro:

    $c = curl_init();
    curl_setopt( $c, CURLOPT_URL,  'http://www.floatrates.com/daily/eur.xml');
    curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $c, CURLOPT_HTTPHEADER, array('Content-type: text/xml; charset=utf-8',));
    curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
    $xml_response = curl_exec($c);
    curl_close($c);                
    
    $sxml= new SimpleXMLElement($xml_response);
    
    $rates= array();
    foreach($sxml->item as $item) { 
        $rates[(string)$item->targetCurrency] = (1/ str_replace(',','',$item->exchangeRate));
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入