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