Picqer_Webhook - Version 1.0.0

Version Notes

First version of the Picqer_Webhook extension to support realtime sync of orders from Magento to Picqer.

Download this release

Release Info

Developer Stephan Groen
Extension Picqer_Webhook
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Picqer/Webhook/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Picqer_Webhook_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ //
6
+ }
app/code/community/Picqer/Webhook/Model/Active.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Picqer_Webhook_Model_Active
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => 1, 'label' => Mage::helper('picqer_webhook')->__('Yes')),
9
+ array('value' => 0, 'label' => Mage::helper('picqer_webhook')->__('No'))
10
+ );
11
+ }
12
+ }
app/code/community/Picqer/Webhook/Model/Orderstate.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Picqer_Webhook_Model_Orderstate
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return array(
8
+ array('value' => 'new', 'label' => Mage::helper('picqer_webhook')->__('New')),
9
+ array('value' => 'pending_payment', 'label' => Mage::helper('picqer_webhook')->__('Pending Payment')),
10
+ array('value' => 'processing', 'label' => Mage::helper('picqer_webhook')->__('Processing')),
11
+ array('value' => 'complete', 'label' => Mage::helper('picqer_webhook')->__('Complete')),
12
+ array('value' => 'closed', 'label' => Mage::helper('picqer_webhook')->__('Closed')),
13
+ array('value' => 'canceled', 'label' => Mage::helper('picqer_webhook')->__('Canceled')),
14
+ array('value' => 'holded', 'label' => Mage::helper('picqer_webhook')->__('On Hold')),
15
+ array('value' => 'payment_review', 'label' => Mage::helper('picqer_webhook')->__('Payment Review')),
16
+ );
17
+ }
18
+ }
app/code/community/Picqer/Webhook/Model/Sales/Order/Webhook.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Picqer_Webhook_Model_Sales_Order_Webhook
4
+ {
5
+
6
+ /**
7
+ * Send order information to Picqer
8
+ *
9
+ * @param null $observer
10
+ */
11
+ public function sendWebhook($observer = null)
12
+ {
13
+ // Only run when configured as active
14
+ $active = Mage::getStoreConfig('picqer_webhook_options/general_settings/picqer_webhook_active');
15
+ if ($active != 1) {
16
+ return;
17
+ }
18
+
19
+ $order = $observer->getOrder();
20
+
21
+ // Only run when correct state is set
22
+ if ( ! $this->hasCorrectState($order)) {
23
+ return;
24
+ }
25
+
26
+ // Get preferences
27
+ $magentoKey = Mage::getStoreConfig('picqer_webhook_options/general_settings/picqer_magento_key');
28
+ $domain = Mage::getStoreConfig('picqer_webhook_options/general_settings/picqer_domain');
29
+
30
+ // Get the API Order Model
31
+ $apiOrder = Mage::getModel('sales/order_api');
32
+ $orderData = $apiOrder->info($order->getIncrementId());
33
+ $orderData['picqer_magento_key'] = $magentoKey;
34
+ $orderData = json_encode($orderData);
35
+
36
+ // Send the order to Picqer
37
+ $this->post('https://' . $domain . '.picqer.com/webshops/magento/orderPush/' . $magentoKey, $orderData);
38
+ }
39
+
40
+
41
+ /**
42
+ * POST data to URL with cURL
43
+ *
44
+ * @param $url
45
+ * @param $data
46
+ *
47
+ * @return mixed
48
+ */
49
+ private function post($url, $data)
50
+ {
51
+ $ch = curl_init();
52
+ $curlConfig = array(
53
+ CURLOPT_URL => $url,
54
+ CURLOPT_POST => true,
55
+ CURLOPT_RETURNTRANSFER => true,
56
+ CURLOPT_SSL_VERIFYPEER => 0,
57
+ CURLOPT_SSL_VERIFYHOST => 0,
58
+ CURLOPT_HTTPHEADER => array(
59
+ 'Content-Type: application/json',
60
+ 'Content-Length: ' . strlen($data)
61
+ ),
62
+ CURLOPT_POSTFIELDS => $data,
63
+ CURLOPT_TIMEOUT => 10
64
+ );
65
+ curl_setopt_array($ch, $curlConfig);
66
+ $result = curl_exec($ch);
67
+ curl_close($ch);
68
+
69
+ return $result;
70
+ }
71
+
72
+
73
+ private function hasCorrectState($order)
74
+ {
75
+ $state = $order->getState();
76
+ $requestedState = Mage::getStoreConfig('picqer_webhook_options/general_settings/picqer_order_state');
77
+
78
+ return $state === $requestedState;
79
+ }
80
+ }
app/code/community/Picqer/Webhook/etc/config.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Picqer_Webhook>
5
+ <version>1.0.0</version>
6
+ </Picqer_Webhook>
7
+ </modules>
8
+ <global>
9
+ <events>
10
+ <sales_order_save_after>
11
+ <observers>
12
+ <!-- Send a webhook to Picqer if order has correct status -->
13
+ <picqer_send_order_webhook>
14
+ <class>Picqer_Webhook_Model_Sales_Order_Webhook</class>
15
+ <method>sendWebhook</method>
16
+ </picqer_send_order_webhook>
17
+ </observers>
18
+ </sales_order_save_after>
19
+ </events>
20
+ <helpers>
21
+ <picqer_webhook>
22
+ <class>Picqer_Webhook_Helper</class>
23
+ </picqer_webhook>
24
+ </helpers>
25
+ <models>
26
+ <picqer_webhook>
27
+ <class>Picqer_Webhook_Model</class>
28
+ </picqer_webhook>
29
+ </models>
30
+ </global>
31
+ <adminhtml>
32
+ <acl>
33
+ <resources>
34
+ <admin>
35
+ <children>
36
+ <system>
37
+ <children>
38
+ <config>
39
+ <children>
40
+ <picqer_webhook_options>
41
+ <title>Store Picqer Webhook Section</title>
42
+ </picqer_webhook_options>
43
+ </children>
44
+ </config>
45
+ </children>
46
+ </system>
47
+ </children>
48
+ </admin>
49
+ </resources>
50
+ </acl>
51
+ </adminhtml>
52
+ <default>
53
+ <picqer_webhook_options>
54
+ <general_settings>
55
+ <picqer_webhook_active>processing</picqer_webhook_active>
56
+ </general_settings>
57
+ </picqer_webhook_options>
58
+ </default>
59
+ </config>
app/code/community/Picqer/Webhook/etc/system.xml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <picqer translate="label" module="picqer_webhook">
5
+ <label>Picqer</label>
6
+ <sort_order>99999</sort_order>
7
+ </picqer>
8
+ </tabs>
9
+ <sections>
10
+ <picqer_webhook_options translate="label" module="picqer_webhook">
11
+ <label>Webhooks</label>
12
+ <tab>picqer</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1000</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general_settings translate="label">
20
+ <label>General settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <picqer_webhook_active>
28
+ <label>Active</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>picqer_webhook/active</source_model>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </picqer_webhook_active>
36
+ <picqer_order_state>
37
+ <label>Order state to push</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>picqer_webhook/orderstate</source_model>
40
+ <sort_order>2</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </picqer_order_state>
45
+ <picqer_magento_key>
46
+ <label>Connection key</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>3</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ </picqer_magento_key>
53
+ <picqer_domain>
54
+ <label>Picqer domain</label>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>4</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+ </picqer_domain>
61
+ </fields>
62
+ </general_settings>
63
+ </groups>
64
+ </picqer_webhook_options>
65
+ </sections>
66
+ </config>
app/etc/modules/Picqer_Webhook.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Picqer_Webhook>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Api/>
9
+ </depends>
10
+ </Picqer_Webhook>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Picqer_Webhook</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Sync your Magento orders realtime to Picqer.</summary>
10
+ <description>This extension add realtime sync of your orders to Picqer Online Inventory Software.</description>
11
+ <notes>First version of the Picqer_Webhook extension to support realtime sync of orders from Magento to Picqer.</notes>
12
+ <authors><author><name>Stephan Groen</name><user>stephangroen</user><email>stephan@picqer.com</email></author></authors>
13
+ <date>2015-07-09</date>
14
+ <time>12:29:17</time>
15
+ <contents><target name="magecommunity"><dir name="Picqer"><dir name="Webhook"><dir name="Helper"><file name="Data.php" hash="135ad557d51b2928099f9d0c368e22cf"/></dir><dir name="Model"><file name="Active.php" hash="38950d5edfa800a68cf52689e136d11c"/><file name="Orderstate.php" hash="00c325a4bcdaef1615a4063596c21f01"/><dir name="Sales"><dir name="Order"><file name="Webhook.php" hash="50b725df5e9a8bf849bd8b74e6ee196b"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="3a1a1fd3fb91b0e62d8ce58aafef65ca"/><file name="system.xml" hash="60824bb96ac26ee22737098ffed1c49b"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Picqer_Webhook.xml" hash="718b9dcfc1ec253e58ed71d61f6f7d6a"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.0</min><max>5.6.9</max></php><extension><name>curl</name><min/><max/></extension></required></dependencies>
18
+ </package>