FarApp_Connector - Version 1.4.0

Version Notes

Added real-time order push to FarApp

Download this release

Release Info

Developer FarApp
Extension FarApp_Connector
Version 1.4.0
Comparing to
See all releases


Code changes from version 1.3.1 to 1.4.0

app/code/community/FarApp/Connector/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class FarApp_Connector_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/community/FarApp/Connector/Model/Observer.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer to handle event
5
+ * Sends JSON data to URL specified in extensions admin settings
6
+ *
7
+ */
8
+ class FarApp_Connector_Model_Observer {
9
+
10
+ /**
11
+ * Used to ensure the event is not fired multiple times
12
+ * http://magento.stackexchange.com/questions/7730/sales-order-save-commit-after-event-triggered-twice
13
+ *
14
+ * @var bool
15
+ */
16
+ private $_processFlag = false;
17
+
18
+ /**
19
+ * Posts order
20
+ *
21
+ * @param Varien_Event_Observer $observer
22
+ * @return GoMedia_Webhook_Model_Observer
23
+ */
24
+ public function postOrder($observer) {
25
+
26
+ // make sure this has not already run
27
+ if (!$this->_processFlag) {
28
+
29
+ /** @var $order Mage_Sales_Model_Order */
30
+ $order = $observer->getEvent()->getOrder();
31
+ $orderStatus = $order->getStatus();
32
+ $url = Mage::getStoreConfig('webhook/order/url', $order['store_id']);
33
+ if (!is_null($orderStatus) && $url) {
34
+ $data = $this->transformOrder($order);
35
+ $response = $this->proxy($data, $url);
36
+
37
+ // save comment
38
+ //$order->addStatusHistoryComment(
39
+ // 'GoMedia Web Hook: Sent, Status: ' . $response->status . " Response: " . $response->body,
40
+ // false
41
+ //);
42
+ $this->_processFlag = true;
43
+ //$order->save();
44
+ }
45
+ }
46
+ return $this;
47
+ }
48
+
49
+
50
+ /**
51
+ * Curl data and return body
52
+ *
53
+ * @param $data
54
+ * @param $url
55
+ * @return stdClass $output
56
+ */
57
+ private function proxy($data, $url) {
58
+
59
+ $output = new stdClass();
60
+ $ch = curl_init();
61
+ $body = json_encode($data);
62
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
63
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
64
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
65
+ //'Accept: application/json',
66
+ 'Content-Type: application/json',
67
+ 'Content-Length: ' . strlen($body),
68
+ // http://stackoverflow.com/questions/11359276/php-curl-exec-returns-both-http-1-1-100-continue-and-http-1-1-200-ok-separated-b
69
+ 'Expect:' // Remove "HTTP/1.1 100 Continue" from response
70
+ ));
71
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60 * 2); // 2 minutes to connect
72
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60 * 4); // 8 minutes to fetch the response
73
+ curl_setopt($ch, CURLOPT_URL, $url);
74
+ curl_setopt($ch, CURLOPT_HEADER, 1);
75
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
76
+
77
+ // ignore cert issues
78
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
79
+
80
+ // execute
81
+ $response = curl_exec($ch);
82
+ $output->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
83
+ curl_close($ch);
84
+
85
+ // handle response
86
+ $arr = explode("\r\n\r\n", $response, 2);
87
+ if (count($arr) == 2) {
88
+ $output->header = $arr[0];
89
+ $output->body = $arr[1];
90
+ } else {
91
+ $output->body = "Unexpected response";
92
+ }
93
+ return $output;
94
+ }
95
+
96
+ /**
97
+ * Transform order into one data object for posting
98
+ */
99
+ /**
100
+ * @param $orderIn Mage_Sales_Model_Order
101
+ * @return mixed
102
+ */
103
+ private function transformOrder($orderIn) {
104
+ $orderOut = $orderIn->getData();
105
+ $orderOut['order_id'] = $orderOut['entity_id'];
106
+ $orderOut['items'] = array();
107
+ foreach ($orderIn->getAllItems() as $item) {
108
+ $orderOut['items'][] = $item->getData();
109
+ }
110
+
111
+ /** @var $customer Mage_Customer_Model_Customer */
112
+ $customer = Mage::getModel('customer/customer')->load($orderIn->getCustomerId());
113
+ $orderOut['customer'] = $customer->getData();
114
+ $orderOut['customer']['customer_id'] = $orderIn->getCustomerId();
115
+
116
+ /** @var $shipping_address Mage_Sales_Model_Order_Address*/
117
+ $shipping_address = $orderIn->getShippingAddress();
118
+ $orderOut['shipping_address'] = $shipping_address->getData();
119
+
120
+ /** @var $shipping_address Mage_Sales_Model_Order_Address*/
121
+ $billing_address = $orderIn->getBillingAddress();
122
+ $orderOut['billing_address'] = $billing_address->getData();
123
+
124
+ /** @var $shipping_address Mage_Sales_Model_Order_Payment*/
125
+ $payment = $orderIn->getPayment()->getData();
126
+
127
+ // remove cc fields
128
+ foreach ($payment as $key => $value) {
129
+ if (strpos($key, 'cc_') !== 0) {
130
+ $orderOut['payment'][$key] = $value;
131
+ }
132
+ }
133
+
134
+ /** @var $orderOut Mage_Core_Model_Session */
135
+ $session = Mage::getModel('core/session');
136
+ $orderOut['visitor'] = $session->getValidatorData();
137
+
138
+ $history = $orderIn->getStatusHistoryCollection();
139
+ $orderOut['status_history'] = $history->getData();
140
+
141
+ return $orderOut;
142
+ }
143
+ }
app/code/community/FarApp/Connector/etc/config.xml CHANGED
@@ -9,7 +9,7 @@
9
  <config>
10
  <modules>
11
  <FarApp_Connector>
12
- <version>1.3.1</version>
13
  </FarApp_Connector>
14
  </modules>
15
  <global>
@@ -29,6 +29,21 @@
29
  </rewrite>
30
  </catalog>
31
  </models>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <farapp_connector module="farapp_connector">
33
  <import_entities>
34
  <catalog_product translate="label">
@@ -79,4 +94,25 @@
79
  </connector>
80
  </routers>
81
  </frontend>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  </config>
9
  <config>
10
  <modules>
11
  <FarApp_Connector>
12
+ <version>1.4.0</version>
13
  </FarApp_Connector>
14
  </modules>
15
  <global>
29
  </rewrite>
30
  </catalog>
31
  </models>
32
+ <events>
33
+ <sales_order_save_after>
34
+ <observers>
35
+ <post_order>
36
+ <class>farapp_connector/observer</class>
37
+ <method>postOrder</method>
38
+ </post_order>
39
+ </observers>
40
+ </sales_order_save_after>
41
+ </events>
42
+ <helpers>
43
+ <connector>
44
+ <class>FarApp_Connector_Helper</class>
45
+ </connector>
46
+ </helpers>
47
  <farapp_connector module="farapp_connector">
48
  <import_entities>
49
  <catalog_product translate="label">
94
  </connector>
95
  </routers>
96
  </frontend>
97
+ <adminhtml>
98
+ <acl>
99
+ <resources>
100
+ <admin>
101
+ <children>
102
+ <system>
103
+ <children>
104
+ <config>
105
+ <children>
106
+ <connector>
107
+ <title>FarApp Module Section</title>
108
+ </connector>
109
+ </children>
110
+ </config>
111
+ </children>
112
+ </system>
113
+ </children>
114
+ </admin>
115
+ </resources>
116
+ </acl>
117
+ </adminhtml>
118
  </config>
app/code/community/FarApp/Connector/etc/system.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <farapp_connector translate="label" module="connector">
4
+ <label>FarApp Connector</label>
5
+ <sort_order>99999</sort_order>
6
+ </farapp_connector>
7
+ </tabs>
8
+ <sections>
9
+ <connector translate="label" module="connector">
10
+ <label>FarApp Connector Settings</label>
11
+ <tab>farapp_connector</tab>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>0</show_in_website>
16
+ <show_in_store>0</show_in_store>
17
+ <groups>
18
+ <order translate="label">
19
+ <label>Order Webhook</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>0</show_in_website>
24
+ <show_in_store>0</show_in_store>
25
+ <fields>
26
+ <url>
27
+ <label>URL</label>
28
+ <frontend_type>text</frontend_type>
29
+ <sort_order>1</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ <comment><![CDATA[This URL is fired when an order is created or updated. The order data is posted to the URL.]]></comment>
34
+ </url>
35
+ </fields>
36
+ </order>
37
+ </groups>
38
+ </connector>
39
+ </sections>
40
+ </config>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>FarApp_Connector</name>
4
- <version>1.3.1</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.farapp.com/signup/">Commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connector to sync product data from FarApp to Magento. FarApp currently supports NetSuite and other backends.</summary>
10
  <description>FarApp is a cloud-based solution for posting product data to storefronts, retrieving orders from storefront and posting fulfillments to storefronts. We support various backends including NetSuite, X-Cart, 3D-Cart, and more. This connector allows full product data posting to Magento from FarApp. It has the the extra benefits of allowing FarApp to dynamically push new product data, automatically creating new attribute options and importing external images (features not provided by Magento).</description>
11
- <notes>Improved missing category error details.</notes>
12
  <authors><author><name>FarApp</name><user>FarApp</user><email>support@farapp.com</email></author></authors>
13
- <date>2016-04-26</date>
14
- <time>19:46:21</time>
15
- <contents><target name="magecommunity"><dir name="FarApp"><dir name="Connector"><dir name="Model"><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="765dc8fbab996f17b9f049cc8aa906a0"/><file name="Array.php" hash="6ca62c702dcb9512ec429563ac1ce1a2"/></dir><dir name="Entity"><file name="Order.php" hash="14a2f735cf8fc5e8f2bcd6682a1e56b1"/></dir></dir><file name="Export.php" hash="01643ef101731c6d98bbc523642f95a0"/><dir name="Import"><dir name="Entity"><file name="Customer.php" hash="376978f635c73605d428037cca8cf594"/><file name="Order.php" hash="38579396825a1bd3ad59de84278085f6"/><file name="Product.php" hash="038143e12f77df56ae844ff6879ca575"/><file name="minVersion2.php" hash="8df670fd68516ba1629304ae8ab6c812"/></dir></dir><file name="Import.php" hash="5f226d5505bf8e258a4e61f43b09b25a"/><dir name="Order"><dir name="Creditmemo"><file name="Api.php" hash="edb85d34679eab92e8990a0dd065632e"/></dir><dir name="Invoice"><file name="Api.php" hash="f133255dae51ab9c44c71ca9cc702d0a"/></dir></dir><dir name="Product"><file name="Api.php" hash="d54b796b7b6ebf466c520cbccd58fb4b"/></dir></dir><dir name="controllers"><file name="ExportController.php" hash="83a48feea4dc3d601b2cef7df2d27110"/><file name="ImportController.php" hash="ec66abaf46073b9491889a199d665992"/><file name="IndexController.php" hash="93918848d3ce7f6ad05688f89a730e75"/></dir><dir name="etc"><file name="api.xml" hash="6178269d7dc6cb7aa1188f059e75a4fc"/><file name="config.xml" hash="c7c8f0139d22010b524491fe1f2024aa"/><file name="wsdl.xml" hash="53aac63b4e1503137d9280b374d51b03"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FarApp_Connector.xml" hash="ff3fe315c70239229cb5ff3a49d40967"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>5.7.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>FarApp_Connector</name>
4
+ <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.farapp.com/signup/">Commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connector to sync product data from FarApp to Magento. FarApp currently supports NetSuite and other backends.</summary>
10
  <description>FarApp is a cloud-based solution for posting product data to storefronts, retrieving orders from storefront and posting fulfillments to storefronts. We support various backends including NetSuite, X-Cart, 3D-Cart, and more. This connector allows full product data posting to Magento from FarApp. It has the the extra benefits of allowing FarApp to dynamically push new product data, automatically creating new attribute options and importing external images (features not provided by Magento).</description>
11
+ <notes>Added real-time order push to FarApp</notes>
12
  <authors><author><name>FarApp</name><user>FarApp</user><email>support@farapp.com</email></author></authors>
13
+ <date>2016-05-22</date>
14
+ <time>21:12:26</time>
15
+ <contents><target name="magecommunity"><dir name="FarApp"><dir name="Connector"><dir name="Helper"><file name="Data.php" hash="60ea63e7acbcdd006c05d3f8528d6b91"/></dir><dir name="Model"><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="765dc8fbab996f17b9f049cc8aa906a0"/><file name="Array.php" hash="6ca62c702dcb9512ec429563ac1ce1a2"/></dir><dir name="Entity"><file name="Order.php" hash="14a2f735cf8fc5e8f2bcd6682a1e56b1"/></dir></dir><file name="Export.php" hash="01643ef101731c6d98bbc523642f95a0"/><dir name="Import"><dir name="Entity"><file name="Customer.php" hash="376978f635c73605d428037cca8cf594"/><file name="Order.php" hash="38579396825a1bd3ad59de84278085f6"/><file name="Product.php" hash="038143e12f77df56ae844ff6879ca575"/><file name="minVersion2.php" hash="8df670fd68516ba1629304ae8ab6c812"/></dir></dir><file name="Import.php" hash="5f226d5505bf8e258a4e61f43b09b25a"/><file name="Observer.php" hash="2b443ab8da2b82f7284df1805595d85c"/><dir name="Order"><dir name="Creditmemo"><file name="Api.php" hash="edb85d34679eab92e8990a0dd065632e"/></dir><dir name="Invoice"><file name="Api.php" hash="f133255dae51ab9c44c71ca9cc702d0a"/></dir></dir><dir name="Product"><file name="Api.php" hash="d54b796b7b6ebf466c520cbccd58fb4b"/></dir></dir><dir name="controllers"><file name="ExportController.php" hash="83a48feea4dc3d601b2cef7df2d27110"/><file name="ImportController.php" hash="ec66abaf46073b9491889a199d665992"/><file name="IndexController.php" hash="93918848d3ce7f6ad05688f89a730e75"/></dir><dir name="etc"><file name="api.xml" hash="6178269d7dc6cb7aa1188f059e75a4fc"/><file name="config.xml" hash="e61da59cf466704a897267da1a112a48"/><file name="system.xml" hash="395c2670f5132a4e617310345185c200"/><file name="wsdl.xml" hash="53aac63b4e1503137d9280b374d51b03"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FarApp_Connector.xml" hash="ff3fe315c70239229cb5ff3a49d40967"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>5.7.0</max></php></required></dependencies>
18
  </package>