Php 以编程方式在Magento中导入货币汇率
我正在使用Magento 1.9.1.0 我希望以编程方式导入所有货币汇率,并希望向所有可用货币添加x%的额外汇率Php 以编程方式在Magento中导入货币汇率,php,magento,magento-1.9,Php,Magento,Magento 1.9,我正在使用Magento 1.9.1.0 我希望以编程方式导入所有货币汇率,并希望向所有可用货币添加x%的额外汇率 // Code for Import Currency Rates $currencyModel = Mage::getModel('directory/currency'); $currencies = $currencyModel->getConfigAllowCurrencies(); $baseCurrencyCode = Mage::app()->getSto
// 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导入货币汇率
如果我能把这个代码放在上面的代码行之前,那就是我的目标
有什么想法吗?我正在使用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));
}
请添加一些您编写的代码示例far@Tomasz请查看我的更新问题。@Salketer请查看我的更新问题。请查看我的新编辑。我需要一些脚本从Webservicex导入原始货币汇率。您似乎已经有了保存货币汇率的Magento代码。此库可能会帮助您获取汇率,然后您可以轻松地操纵该汇率+x%