0

Webservicex has stopped working, how can I make my custom Currency Rates? Maybe someone has already done, or advise the site with open api.

config.xml

<?xml version="1.0" ?>
<config>
    <modules>
        <Icandy_ForeignCurrency>
            <version>1.0.0</version>
        </Icandy_ForeignCurrency>
    </modules>
    <global>
        <currency>
            <import>
                <services>
                    <foreign>
                        <name>Foreign currency</name>
                        <model>foreigncurrency/currency_import_foreign</model>
                    </foreign>
                </services>
            </import>
        </currency>
        <models>
            <foreigncurrency>
                <class>Icandy_ForeignCurrency_Model</class>
            </foreigncurrency>
        </models>
    </global>
</config>

model->currency->import->foreign.php

class Icandy_ForeignCurrency_Model_Currency_Import_Foreign extends Mage_Directory_Model_Currency_Import_Abstract
{
    protected $_url = 'https://api.ratesapi.io/api/latest?base={{CURRENCY_FROM}}&symbols={{CURRENCY_TO}}';
    protected $_messages = array();

    protected $_httpClient;

    public function __construct()
    {
        $this->_httpClient = new Varien_Http_Client();
    }

    protected function _convert($currencyFrom, $currencyTo, $retry=0)
    {
        $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
        $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);

        try {
            $response = $this->_httpClient
                ->setUri($url)
                ->setConfig(array('timeout' => Mage::getStoreConfig('currency/foreign/timeout')))
                ->request('GET')
                ->getBody();
            $xml = simplexml_load_string($response, null, LIBXML_NOERROR);
            if( !$xml ) {
                $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
                return null;
            }
            return (float) $xml;
        }
        catch (Exception $e) {
            if( $retry == 0 ) {
                $this->_convert($currencyFrom, $currencyTo, 1);
            } else {
                $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
            }
        }
    }
}

Why does not see my model. enter image description here

When trying to print my model gives

/var/www/i/icandy/web/app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php:74: bool(false)

2
  • do you want automatic currency rate updater ?
    – Pawan
    Apr 10 '19 at 14:50
  • Yes. But see my updated question. Apr 10 '19 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.