inovarti_quitar - Version 0.1.0

Version Notes

Versão 0.1.0
- API para integrar com Quitar

Download this release

Release Info

Developer Inovarti
Extension inovarti_quitar
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Inovarti/Quitar/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ class Inovarti_Quitar_Helper_Data extends Mage_Core_Helper_Abstract {
11
+
12
+ }
app/code/community/Inovarti/Quitar/Model/Api.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ class Inovarti_Quitar_Model_Api extends Mage_Api_Model_Resource_Abstract {
11
+
12
+ const LIMIT = 50;
13
+
14
+ protected $_resource;
15
+ protected $_connection;
16
+
17
+ public function orders($params) {
18
+ $params = json_decode($params, true);
19
+
20
+ $limit = $this->_getParamValue($params, 'limit', self::LIMIT);
21
+ $orderId = $this->_getParamValue($params, 'orderId');
22
+
23
+ $select = $this->_getConnection()
24
+ ->select()
25
+ ->from(array('o' => $this->_getResource()->getTableName('sales/order')), array(
26
+ 'OrderId' => 'entity_id',
27
+ 'IncrementId' => 'increment_id',
28
+ 'TotalCost' => 'base_grand_total',
29
+ 'Email' => 'customer_email',
30
+ ))
31
+ ->join(array('a' => $this->_getResource()->getTableName('sales/order_address')), 'a.parent_id = o.entity_id', array(
32
+ 'FirstName' => 'firstname',
33
+ 'LastName' => 'lastname',
34
+ 'Phone' => 'telephone',
35
+ 'City' => 'city',
36
+ 'Address' => $this->_getDbExprField('address'),
37
+ 'More' => $this->_getDbExprField('more'),
38
+ 'Number' => $this->_getDbExprField('number'),
39
+ 'ZipCode' => 'postcode',
40
+ 'Reverse' => new Zend_Db_Expr('0')
41
+ ))
42
+ ->joinLeft(array('r' => $this->_getResource()->getTableName('directory/country_region')), 'r.region_id = a.region_id', array(
43
+ 'State' => 'code'
44
+ ))
45
+ ->joinLeft(array('t' => $this->_getResource()->getTableName('sales/shipment_track')), 't.order_id = o.entity_id', array(
46
+ 'TrackingNumber' => 'track_number'
47
+ ))
48
+ ->where('o.status NOT IN(?)', array('canceled', 'holded'))
49
+ ->where('a.address_type = ?', 'shipping')
50
+ ->where('t.carrier_code LIKE ?', '%correios%')
51
+ ->order('o.entity_id ASC')
52
+ ->limit($limit);
53
+
54
+ if ($orderId) {
55
+ $select->where('o.entity_id > ?', $orderId);
56
+ }
57
+
58
+ return json_encode($this->_getConnection()->fetchAll($select));
59
+ }
60
+
61
+ protected function _getDbExprField($field) {
62
+ $line = Mage::getStoreConfig('quitar/fields/' . $field);
63
+ if ($line) {
64
+ $expr = 'SUBSTRING_INDEX(SUBSTRING_INDEX(a.street, "\n", ' . $line . '), "\n", -1)';
65
+ } else {
66
+ $expr = '""';
67
+ }
68
+
69
+ return new Zend_Db_Expr($expr);
70
+ }
71
+
72
+ protected function _getOrderIdByIncrementId($incrementId) {
73
+ $select = $this->_getConnection()
74
+ ->select()
75
+ ->from(array('o' => $this->_getResource()->getTableName('sales/order')), array('entity_id'))
76
+ ->where('o.increment_id = ?', $incrementId);
77
+ Mage::log("_getOrderIdByIncrementId(): " . print_r($select->__toString(), 1));
78
+ return $this->_getConnection()->fetchOne($select);
79
+ }
80
+
81
+ protected function _getParamValue($params, $key, $default = null) {
82
+ if (isset($params[$key]) && $params[$key]) {
83
+ $value = $params[$key];
84
+ } else {
85
+ $value = $default;
86
+ }
87
+
88
+ return $value;
89
+ }
90
+
91
+ protected function _getResource() {
92
+ if (is_null($this->_resource)) {
93
+ $this->_resource = Mage::getSingleton('core/resource');
94
+ }
95
+ return $this->_resource;
96
+ }
97
+
98
+ protected function _getConnection() {
99
+ if (is_null($this->_connection)) {
100
+ $this->_connection = $this->_getResource()->getConnection('core_read');
101
+ }
102
+ return $this->_connection;
103
+ }
104
+
105
+ }
app/code/community/Inovarti/Quitar/Model/System/Config/Source/Line.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ class Inovarti_Quitar_Model_System_Config_Source_Line {
11
+
12
+ protected $_options;
13
+
14
+ public function toOptionArray() {
15
+ if (!$this->_options) {
16
+ $this->_options = array(
17
+ array('value' => '', 'label' => Mage::helper('quitar')->__('Empty')),
18
+ array('value' => 1, 'label' => Mage::helper('quitar')->__('Street Line %s', 1)),
19
+ array('value' => 2, 'label' => Mage::helper('quitar')->__('Street Line %s', 2)),
20
+ array('value' => 3, 'label' => Mage::helper('quitar')->__('Street Line %s', 3)),
21
+ array('value' => 4, 'label' => Mage::helper('quitar')->__('Street Line %s', 4))
22
+ );
23
+ }
24
+ return $this->_options;
25
+ }
26
+
27
+ }
app/code/community/Inovarti/Quitar/etc/adminhtml.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ -->
11
+ <config>
12
+ <acl>
13
+ <resources>
14
+ <admin>
15
+ <children>
16
+ <system>
17
+ <children>
18
+ <config>
19
+ <children>
20
+ <quitar translate="title" module="quitar">
21
+ <title>Quitar</title>
22
+ <sort_order>200</sort_order>
23
+ </quitar>
24
+ </children>
25
+ </config>
26
+ </children>
27
+ </system>
28
+ </children>
29
+ </admin>
30
+ </resources>
31
+ </acl>
32
+ </config>
app/code/community/Inovarti/Quitar/etc/api.xml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ -->
11
+ <config>
12
+ <api>
13
+ <resources>
14
+ <quitar translate="title" module="quitar">
15
+ <model>quitar/api</model>
16
+ <title>Quitar Resource</title>
17
+ <acl>quitar</acl>
18
+ <methods>
19
+ <orders translate="title" module="quitar">
20
+ <title>Order List</title>
21
+ <method>orders</method>
22
+ <acl>quitar/orders</acl>
23
+ </orders>
24
+ </methods>
25
+ <faults module="quitar">
26
+ <not_exists>
27
+ <code>100</code>
28
+ <message>Order not exists.</message>
29
+ </not_exists>
30
+ </faults>
31
+ </quitar>
32
+ </resources>
33
+ <acl>
34
+ <resources>
35
+ <quitar translate="title" module="quitar">
36
+ <title>Quitar Resource</title>
37
+ <sort_order>100</sort_order>
38
+ <orders translate="title" module="quitar">
39
+ <title>Order List</title>
40
+ <sort_order>10</sort_order>
41
+ </orders>
42
+ </quitar>
43
+ </resources>
44
+ </acl>
45
+ </api>
46
+ </config>
app/code/community/Inovarti/Quitar/etc/config.xml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ -->
11
+ <config>
12
+ <modules>
13
+ <Inovarti_Quitar>
14
+ <version>0.1.0</version>
15
+ </Inovarti_Quitar>
16
+ </modules>
17
+ <global>
18
+ <models>
19
+ <quitar>
20
+ <class>Inovarti_Quitar_Model</class>
21
+ </quitar>
22
+ </models>
23
+ <helpers>
24
+ <quitar>
25
+ <class>Inovarti_Quitar_Helper</class>
26
+ </quitar>
27
+ </helpers>
28
+ </global>
29
+ <adminhtml>
30
+ <translate>
31
+ <modules>
32
+ <Inovarti_Quitar>
33
+ <files>
34
+ <default>Inovarti_Quitar.csv</default>
35
+ </files>
36
+ </Inovarti_Quitar>
37
+ </modules>
38
+ </translate>
39
+ </adminhtml>
40
+ <default>
41
+ <quitar>
42
+ <fields>
43
+ <address>1</address>
44
+ <number>2</number>
45
+ <more>3</more>
46
+ </fields>
47
+ </quitar>
48
+ </default>
49
+ </config>
app/code/community/Inovarti/Quitar/etc/system.xml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Quitar
5
+ *
6
+ * @category    Quitar
7
+ * @package     Inovarti_Quitar
8
+ * @copyright   Copyright (c) 2013 Inovarti. (http://www.inovarti.com.br)
9
+ */
10
+ -->
11
+ <config>
12
+ <tabs>
13
+ <inovarti translate="label" module="quitar">
14
+ <label>Inovarti</label>
15
+ <sort_order>299</sort_order>
16
+ </inovarti>
17
+ </tabs>
18
+ <sections>
19
+ <quitar translate="label" module="quitar">
20
+ <label>Quitar</label>
21
+ <tab>inovarti</tab>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>200</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <groups>
28
+ <fields translate="label">
29
+ <label>Address Fields</label>
30
+ <sort_order>20</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>0</show_in_website>
33
+ <show_in_store>0</show_in_store>
34
+ <fields>
35
+ <address translate="label">
36
+ <label>Address</label>
37
+ <frontend_type>select</frontend_type>
38
+ <source_model>quitar/system_config_source_line</source_model>
39
+ <sort_order>10</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </address>
44
+ <number translate="label">
45
+ <label>Number</label>
46
+ <frontend_type>select</frontend_type>
47
+ <source_model>quitar/system_config_source_line</source_model>
48
+ <sort_order>20</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>0</show_in_website>
51
+ <show_in_store>0</show_in_store>
52
+ </number>
53
+ <more translate="label">
54
+ <label>More</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>quitar/system_config_source_line</source_model>
57
+ <sort_order>30</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>0</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ </more>
62
+ </fields>
63
+ </fields>
64
+ </groups>
65
+ </quitar>
66
+ </sections>
67
+ </config>
app/etc/modules/Inovarti_Quitar.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Inovarti_Quitar>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ </Inovarti_Quitar>
7
+ </modules>
8
+ </config>
app/locale/pt_BR/Inovarti_Quitar.csv ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ "General","Geral"
2
+ "Initial Order Number","Número do Pedido Inicial"
3
+ "Address Fields","Campos do Endereço"
4
+ "Address","Endereço"
5
+ "Number","Número"
6
+ "More","Complemento"
7
+ "Empty","Vazio"
8
+ "Street Line %s","Linha %s do endereço de rua"
9
+ "Quitar Resource","Quitar"
10
+ "Order List","Lista de Pedidos com Envío"
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>inovarti_quitar</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>Inovarti License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>API para integrar com Quitar</summary>
10
+ <description>http://quitar.com.br</description>
11
+ <notes>Vers&#xE3;o 0.1.0&#xD;
12
+ - API para integrar com Quitar </notes>
13
+ <authors><author><name>Inovarti</name><user>Inovarti</user><email>suporte@inovarti.com.br</email></author></authors>
14
+ <date>2014-05-23</date>
15
+ <time>02:29:12</time>
16
+ <contents><target name="magecommunity"><dir name="Inovarti"><dir name="Quitar"><dir name="Helper"><file name="Data.php" hash="06b714f1b5469bf7ec16f8296bb93ba0"/></dir><dir name="Model"><file name="Api.php" hash="b56a1406fe61755a9f46b608cae4527b"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Line.php" hash="fd44b8d5f73dbc0ed46278da7a60b5d6"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="b185a6666c39a4c59797b2e7fef3f110"/><file name="api.xml" hash="88946727805f8c7668b69ee9d3f21c51"/><file name="config.xml" hash="e8cc5011ac3d44c7e3a5f1ae7aefdbfb"/><file name="system.xml" hash="762debd0abc0a5ce779747f04c1eacc1"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Inovarti_Quitar.xml" hash="9bd323439b1609a80cd10af97411cc06"/></dir></target><target name="magelocale"><dir><dir name="pt_BR"><file name="Inovarti_Quitar.csv" hash="704769802b63f9907895819c71ddf2e5"/></dir></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>