currency-rate-importer - Version 0.1.0

Version Notes

First stable release

Download this release

Release Info

Developer Tarun Mukherjee
Extension currency-rate-importer
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Escoin/Directory/Model/Currency/Import/Yahoofinance.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Escoin_Directory_Model_Currency_Import_Yahoofinance extends Mage_Directory_Model_Currency_Import_Abstract
3
+ {
4
+ protected $_url = 'http://quote.yahoo.com/d/quotes.csv?s={{CURRENCY_FROM}}{{CURRENCY_TO}}=X&f=l1&e=.csv';
5
+ protected $_messages = array();
6
+
7
+ protected function _convert($currencyFrom, $currencyTo, $retry=0)
8
+ {
9
+ $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
10
+ $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
11
+
12
+ try {
13
+ sleep(1); //Be nice to Yahoo, they don't have a lot of hi-spec servers
14
+
15
+ $handle = fopen($url, "r");
16
+
17
+ $exchange_rate = fread($handle, 2000);
18
+
19
+ fclose($handle);
20
+
21
+ if( !$exchange_rate ) {
22
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
23
+ return null;
24
+ }
25
+ return (float) $exchange_rate * 1.0; // change 1.0 to influence rate;
26
+ }
27
+ catch (Exception $e) {
28
+ if( $retry == 0 ) {
29
+ $this->_convert($currencyFrom, $currencyTo, 1);
30
+ } else {
31
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
32
+ }
33
+ }
34
+ }
35
+ }
app/code/local/Escoin/Directory/etc/config.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Escoin_Directory>
5
+ <version>1.0</version>
6
+ </Escoin_Directory>
7
+ </modules>
8
+ <global>
9
+ <currency>
10
+ <import>
11
+ <services>
12
+ <yahoofinance>
13
+ <name>Yahoo Finance</name>
14
+ <model>Escoin_Directory_Model_Currency_Import_Yahoofinance</model>
15
+ </yahoofinance>
16
+ </services>
17
+ </import>
18
+ </currency>
19
+ </global>
20
+ </config>
app/etc/modules/Escoin_Directory.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Escoin_Directory>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Escoin_Directory>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>currency-rate-importer</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Currency rate importer</summary>
10
+ <description>Uses Yahoo Finance to import currency rates for magento store</description>
11
+ <notes>First stable release</notes>
12
+ <authors><author><name>Tarun Mukherjee</name><user>tmukherjee13</user><email>tmukherjee13@gmail.com</email></author></authors>
13
+ <date>2014-02-12</date>
14
+ <time>18:19:34</time>
15
+ <contents><target name="magelocal"><dir><dir name="Escoin"><dir name="Directory"><dir name="Model"><dir name="Currency"><dir name="Import"><file name="Yahoofinance.php" hash="832145853c8c9cc7ef0869a94dc87e75"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="006f6d548d24fec08fdb1511bb38f65e"/></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Escoin_Directory.xml" hash="4e3ec626caa7ca70f1ca94875535c112"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>