bb_bnr - Version 1.0.0

Version Notes

mage-bnr-currency-import

Download this release

Release Info

Developer George Babarus
Extension bb_bnr
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Bb/Bnr/Model/Currency/Import/Bnr.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //include_once 'Bnr/Api.php';
3
+
4
+ /**
5
+ * George Babarus extension for Magento
6
+ *
7
+ * Long description of this file (if any...)
8
+ *
9
+ * NOTICE OF LICENSE
10
+ *
11
+ * This source file is subject to the Open Software License (OSL 3.0)
12
+ * that is bundled with this package in the file LICENSE.txt.
13
+ * It is also available through the world-wide-web at this URL:
14
+ * http://opensource.org/licenses/osl-3.0.php
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade
19
+ * the Bb TopMenu module to newer versions in the future.
20
+ * If you wish to customize the Bb TopMenu module for your needs
21
+ * please refer to http://www.magentocommerce.com for more information.
22
+ *
23
+ * @category Bb
24
+ * @package Bb_TopMenu
25
+ * @copyright Copyright (C) 2014 http://www.babarus.ro
26
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27
+ */
28
+ /**
29
+ *
30
+ * Currency rate import model (From www.bnr.net)
31
+ *
32
+ * @category Bb
33
+ * @package Bb_Bnr
34
+ * @subpackage Block
35
+ * @author George Babarus <george.babarus@gmail.com>
36
+ */
37
+ class Bb_Bnr_Model_Currency_Import_Bnr extends Mage_Directory_Model_Currency_Import_Abstract
38
+ {
39
+ protected $_url = 'http://www.bnr.ro/nbrfxrates.xml';
40
+ protected $_messages = array();
41
+
42
+ /**
43
+ * HTTP client
44
+ *
45
+ * @var Varien_Http_Client
46
+ */
47
+ protected $_httpClient;
48
+
49
+ public function __construct()
50
+ {
51
+ $this->_httpClient = new Bnr_Api();
52
+ $this->_httpClient->load($this->_url);
53
+ }
54
+
55
+ protected function _convert($currencyFrom, $currencyTo, $retry=0)
56
+ {
57
+ if (strtoupper($currencyFrom) != 'RON' && strtoupper($currencyTo) != 'RON' ){
58
+ return null;
59
+ }
60
+
61
+ try {
62
+ if (strtoupper($currencyFrom) === 'RON') {
63
+ $value = 1 / floatval($this->_httpClient->getRate($currencyTo));
64
+ }elseif(strtoupper($currencyTo) === 'RON') {
65
+ $value = floatval($this->_httpClient->getRate($currencyFrom));
66
+ } else {
67
+ $this->_messages[] = Mage::helper('directory')->__('Bnr method is applied only for %s <> %s',$currencyFrom, $currencyTo);
68
+ }
69
+
70
+ if( empty($value)) {
71
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s. ( %s <> %s)', $this->_url, $currencyFrom, $currencyTo);
72
+ return null;
73
+
74
+ }
75
+ return (float) $value;
76
+ }
77
+ catch (Exception $e) {
78
+ if( $retry === 0 ) {
79
+ $this->_convert($currencyFrom, $currencyTo, 1);
80
+ } else {
81
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s. ( %s <> %s)', $this->_url, $currencyFrom, $currencyTo);
82
+ }
83
+ }
84
+ return floatval(0);
85
+ }
86
+
87
+
88
+ /**
89
+ * Saving currency rates
90
+ *
91
+ * @param array $rates
92
+ * @return Mage_Directory_Model_Currency_Import_Abstract
93
+ */
94
+ protected function _saveRates($rates)
95
+ {
96
+ Mage::getModel('directory/currency')
97
+ ->saveRates($rates);
98
+
99
+ return $this;
100
+ }
101
+
102
+
103
+ }
104
+
app/code/community/Bb/Bnr/etc/adminhtml.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <bb_products>
5
+ <children>
6
+ <bb_bnr>
7
+ <title>BNR</title>
8
+ <sort_order>0</sort_order>
9
+ <action>adminhtml/system_config/edit/section/currency</action>
10
+ <children>
11
+ <bb_bnr>
12
+ <title>Configure BNR currency import</title>
13
+ <sort_order>0</sort_order>
14
+ <action>adminhtml/system_config/edit/section/currency</action>
15
+ </bb_bnr>
16
+ </children>
17
+ </bb_bnr>
18
+ </children>
19
+ </bb_products>
20
+
21
+ </menu>
22
+
23
+ <acl>
24
+ <resources>
25
+ <all>
26
+ <title>Allow Everything</title>
27
+ </all>
28
+ <admin>
29
+ <children>
30
+ <bb_products>
31
+ <title>BB Products - Menu</title>
32
+ <sort_order>1</sort_order>
33
+ <children>
34
+ <bb_bnr>
35
+ <title>BNR</title>
36
+ <sort_order>0</sort_order>
37
+ <children>
38
+ <bb_bnr>
39
+ <title>Configure BNR currency import</title>
40
+ <sort_order>0</sort_order>
41
+ </bb_bnr>
42
+ </children>
43
+ </bb_bnr>
44
+ </children>
45
+ </bb_products>
46
+ </children>
47
+ </admin>
48
+ </resources>
49
+ </acl>
50
+ </config>
app/code/community/Bb/Bnr/etc/config.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Bb_Bnr>
5
+ <version>0.1.0</version>
6
+ </Bb_Bnr>
7
+ </modules>
8
+ <global>
9
+ <currency>
10
+ <import>
11
+ <services>
12
+ <bnr>
13
+ <name>BNR RON</name>
14
+ <model>bb_bnr/currency_import_bnr</model>
15
+ </bnr>
16
+ </services>
17
+ </import>
18
+ </currency>
19
+
20
+ <models>
21
+ <bb_bnr>
22
+ <class>Bb_Bnr_Model</class>
23
+ </bb_bnr>
24
+ </models>
25
+ </global>
26
+ </config>
app/code/community/Bb/Core/Helper/Data.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Bb extension for Magento - fully suport - easy to use
5
+ *
6
+ *
7
+ * @category Bb
8
+ * @package Bb_Slider
9
+ * @copyright Copyright (C) 2014 Bb (http://www.babarus.ro/)
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ *
12
+ * @author George Babarus <george.babarus@gmail.com>
13
+ *
14
+ */
15
+ class Bb_Core_Helper_Data extends Mage_Adminhtml_Helper_Data
16
+ {
17
+
18
+
19
+ }
app/code/community/Bb/Core/controllers/Adminhtml/BbModulesController.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Bb extension for Magento - fully suport - easy to use
5
+ *
6
+ *
7
+ * @category Bb
8
+ * @package Bb_Slider
9
+ * @copyright Copyright (C) 2014 Bb (http://www.babarus.ro/)
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ *
12
+ * @author George Babarus <george.babarus@gmail.com>
13
+ *
14
+ */
15
+ class Bb_Core_Adminhtml_BbModulesController extends Mage_Adminhtml_Controller_Action
16
+ {
17
+
18
+ public function init()
19
+ {
20
+ parent::init();
21
+
22
+ $this->_setActiveMenu('bb');
23
+
24
+ }
25
+
26
+
27
+ /**
28
+ * help user to use id
29
+ */
30
+ public function productsAction()
31
+ {
32
+ $this->loadLayout();
33
+ $this->renderLayout();
34
+ }
35
+
36
+
37
+ protected function _isAllowed()
38
+ {
39
+ return Mage::getSingleton('admin/session')->isAllowed('bb_slider');
40
+ }
41
+
42
+ }
app/code/community/Bb/Core/etc/adminhtml.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <bb_products>
5
+ <title>BB Products</title>
6
+ <sort_order>99999</sort_order>
7
+ <action>adminhtml/bbModules/products</action>
8
+ <children>
9
+ <news>
10
+ <title>News</title>
11
+ <sort_order>0</sort_order>
12
+ <action>adminhtml/bbModules/products</action>
13
+ </news>
14
+ </children>
15
+ </bb_products>
16
+
17
+ </menu>
18
+
19
+ <acl>
20
+ <resources>
21
+ <all>
22
+ <title>Allow Everything</title>
23
+ </all>
24
+ <admin>
25
+ <children>
26
+ <bb_products>
27
+ <title>BB Products - Menu</title>
28
+ <sort_order>1</sort_order>
29
+ <children>
30
+ <news>
31
+ <title>News</title>
32
+ <sort_order>0</sort_order>
33
+ </news>
34
+ </children>
35
+ </bb_products>
36
+ </children>
37
+ </admin>
38
+ </resources>
39
+ </acl>
40
+ </config>
app/code/community/Bb/Core/etc/config.xml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <config>
3
+ <modules>
4
+ <Bb_Core>
5
+ <version>1.0.0</version>
6
+ </Bb_Core>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <bb_core>
11
+ <class>Bb_Core_Helper</class>
12
+ </bb_core>
13
+ </helpers>
14
+ </global>
15
+ <frontend>
16
+ <routers>
17
+ <bb_core>
18
+ <args>
19
+ <modules>
20
+ <Bb_Core>Bb_Core</Bb_Core>
21
+ </modules>
22
+ </args>
23
+ </bb_core>
24
+ </routers>
25
+
26
+ <translate>
27
+ <modules>
28
+ <bb_core>
29
+ <files>
30
+ <default>Bb_Core.csv</default>
31
+ </files>
32
+ </bb_core>
33
+ </modules>
34
+ </translate>
35
+ <layout>
36
+ <updates>
37
+ <bb_core>
38
+ <file>bb_core.xml</file>
39
+ </bb_core>
40
+ </updates>
41
+ </layout>
42
+ </frontend>
43
+ <adminhtml>
44
+ <layout>
45
+ <updates>
46
+ <bb_core>
47
+ <file>bb_core.xml</file>
48
+ </bb_core>
49
+ </updates>
50
+ </layout>
51
+
52
+ </adminhtml>
53
+ <admin>
54
+ <routers>
55
+ <adminhtml>
56
+ <args>
57
+ <modules>
58
+ <Bb_Core before="Mage_Adminhtml">Bb_Core_Adminhtml</Bb_Core>
59
+ </modules>
60
+ </args>
61
+ </adminhtml>
62
+ </routers>
63
+ </admin>
64
+
65
+ </config>
app/etc/modules/Bb_Bnr.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Bb_Bnr>
5
+ <version>1.0.0</version>
6
+ <codePool>community</codePool>
7
+ <active>true</active>
8
+ </Bb_Bnr>
9
+ </modules>
10
+ </config>
app/etc/modules/Bb_Core.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+
6
+ <Bb_Core>
7
+ <active>true</active>
8
+ <codePool>community</codePool>
9
+ <depends>
10
+ </depends>
11
+ </Bb_Core>
12
+
13
+
14
+ </modules>
15
+ </config>
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>bb_bnr</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Automatically import currency rate between RON and others accepted currencies by BNR</summary>
10
+ <description>This extension will provide you an automatically currency exchange tool for BNR (Banca Nationala Romana). &#xD;
11
+ &#xD;
12
+ &lt;h3&gt;RON currency import &lt;/h3&gt; &#xD;
13
+ You can schedule your store to import the currency on cron run. See the screen shot for more details. &#xD;
14
+ &#xD;
15
+ &lt;a href="http://www.babarus.ro/developement/magento-commerce/modules"&gt;Technical information&lt;/a&gt;</description>
16
+ <notes>mage-bnr-currency-import</notes>
17
+ <authors><author><name>George Babarus</name><user>MAG000308246</user><email>george.babarus@gmail.com</email></author></authors>
18
+ <date>2014-11-17</date>
19
+ <time>12:47:00</time>
20
+ <contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Bb"><dir name="Bnr"><dir name="Model"><dir name="Currency"><dir name="Import"><file name="Bnr.php" hash="fcd336dbf4fe9c810605cc7a9990a26f"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="b9a1f1d81705f04ba838818740a8b647"/><file name="config.xml" hash="7c0435f896a78c4cca35e94bfa25b9d4"/></dir></dir><dir name="Core"><dir name="Helper"><file name="Data.php" hash="7faefd6e95218125d6621d168279961f"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="BbModulesController.php" hash="02c28acf9adb3205eccdb193fddf2a88"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="7534028c5bb1f226a001ab63324103ef"/><file name="config.xml" hash="30d6037810e87f55c8843bcbb3393ea6"/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Bb_Core.xml" hash="321e49727c3d620d9e4e681f41e1c830"/><file name="Bb_Bnr.xml" hash="2b90103502c11e6bfe84a960f108ebaa"/></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.3.1</min><max>5.6.0</max></php></required></dependencies>
23
+ </package>