2015-10-06 62 views
0

我正在使用Magento 1.9.1.0。以編程方式導入Magento貨幣匯率

我想以編程方式導入我所有的貨幣匯率,並且想向所有可用貨幣添加x%額外費用。

// 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 
} 

如何從Webservicex導入貨幣匯率?

如果我可以將這段代碼放在上面這行代碼那就是我的目標。

任何想法?

+0

請加你寫了這麼遠一些代碼樣本 – Tomasz

+0

@Tomasz請看看到我更新的問題。 – Naresh

+0

@Salketer請看看我更新的問題。 – Naresh

回答

0

林正在使用floatrates.com從歐元獲得匯率:

$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)); 
    }