Addedbytes_Pushover - Version 0.1.0

Version Notes

This release includes the base functionality. It allows you to link multiple Pushover accounts to your Magento stores and receive a notification whenever a new order is placed.

Download this release

Release Info

Developer AddedBytes
Extension Addedbytes_Pushover
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Addedbytes/Pushover/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Addedbytes_Pushover_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
app/code/local/Addedbytes/Pushover/Model/Observer.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Addedbytes_Pushover_Model_Observer extends Mage_Core_Model_Abstract
3
+ {
4
+ /**
5
+ * Observer method called on sales_order_place_after event
6
+ */
7
+ public function newOrderNotification($observer)
8
+ {
9
+ // Get order
10
+ $order = $observer->getEvent()->getOrder();
11
+
12
+ // Check there is an order ID in case this was another event triggering the observer
13
+ $incrementId = $order->getIncrementId();
14
+ if (!$incrementId) {
15
+ return true;
16
+ }
17
+
18
+ $messageTitle = 'New Order ' . $incrementId();
19
+ $messageText = 'A new order was placed on your Magento store by "' . $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname() . '" for ' . Mage::helper('checkout')->formatPrice($order->getGrandTotal());
20
+ $orderUrl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('order_id' => $order->getId()));
21
+
22
+ self::sendToPushover($messageTitle, $messageText, $orderUrl);
23
+ }
24
+
25
+ /**
26
+ * Observer method called on config save. Check info and send notification.
27
+ */
28
+ public function confirmConfiguration($observer)
29
+ {
30
+ $messageTitle = 'Configuration Passed';
31
+ $messageText = 'This message is confirmation that the configuration provided for the Added Bytes Pushover extension is working correctly.';
32
+
33
+ self::sendToPushover($messageTitle, $messageText);
34
+ }
35
+
36
+ /**
37
+ * Send notification to linked pushover accounts
38
+ */
39
+ public static function sendToPushover($strTitle, $strMessage, $strUrl = '')
40
+ {
41
+
42
+ // Check module is enabled
43
+ $isEnabled = Mage::getStoreConfig('pushover/pushover_options/pushover_active', Mage::app()->getStore());
44
+ if ($isEnabled != 1) {
45
+ return false;
46
+ }
47
+
48
+ // Check curl is available
49
+ if (!function_exists('curl_version')) {
50
+ Mage::log('[Pushover] Curl is not available.', Zend_Log::INFO, 'addedbytes.log');
51
+ return false;
52
+ }
53
+
54
+ // Check token
55
+ $token = Mage::getStoreConfig('pushover/pushover_settings/pushover_api_token', Mage::app()->getStore());
56
+ if ($token == '') {
57
+ // No token set
58
+ Mage::log('[Pushover] Application token not set.', Zend_Log::INFO, 'addedbytes.log');
59
+ return false;
60
+ }
61
+
62
+ $userKeysString = Mage::getStoreConfig('pushover/pushover_settings/pushover_user_keys', Mage::app()->getStore());
63
+ if ($userKeysString == '') {
64
+ // No user key set
65
+ Mage::log('[Pushover] No user keys set.', Zend_Log::INFO, 'addedbytes.log');
66
+ return false;
67
+ }
68
+
69
+ // Set curl options
70
+ $curlh = curl_init();
71
+ curl_setopt($curlh, CURLOPT_URL, 'https://api.pushover.net/1/messages.json');
72
+ curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
73
+ curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 1);
74
+ curl_setopt($curlh, CURLOPT_TIMEOUT, 3);
75
+
76
+ $success = true;
77
+
78
+ $userKeys = explode(',', $userKeysString);
79
+ foreach ($userKeys as $userKey) {
80
+ curl_setopt(
81
+ $curlh,
82
+ CURLOPT_POSTFIELDS,
83
+ array(
84
+ 'token' => $token,
85
+ 'user' => trim($userKey),
86
+ 'title' => $strTitle,
87
+ 'message' => $strMessage,
88
+ 'url' => $strUrl,
89
+ )
90
+ );
91
+ // Send notification
92
+ $result = curl_exec($curlh);
93
+ $resultArray = json_decode($result, true);
94
+ if ($resultArray['status'] != 1) {
95
+ // Check for token error
96
+ if ((isset($resultArray['token'])) && ($resultArray['token'] == 'invalid')) {
97
+ $success = false;
98
+ Mage::getSingleton('core/session')->addError('Unable to send confirmation message with given application token: "' . $token . '".');
99
+ break;
100
+ }
101
+ $success = false;
102
+ Mage::getSingleton('core/session')->addError('Unable to send confirmation message to device with key: "' . $userKey . '".');
103
+ }
104
+ }
105
+ curl_close($curlh);
106
+
107
+ if ($success) {
108
+ Mage::getSingleton('core/session')->addSuccess('Pushover configuration was saved successfully. You should receive confirmation messages on linked devices.');
109
+ }
110
+
111
+ return true;
112
+ }
113
+ }
app/code/local/Addedbytes/Pushover/etc/config.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Addedbytes_Pushover>
5
+ <version>0.1.0</version>
6
+ </Addedbytes_Pushover>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <addedbytespushover>
11
+ <class>Addedbytes_Pushover_Model</class>
12
+ </addedbytespushover>
13
+ </models>
14
+ <helpers>
15
+ <addedbytes_pushover>
16
+ <class>Addedbytes_Pushover_Helper</class>
17
+ </addedbytes_pushover>
18
+ </helpers>
19
+ <events>
20
+ <sales_order_place_after>
21
+ <observers>
22
+ <addedbytes_pushover>
23
+ <class>addedbytespushover/observer</class>
24
+ <method>newOrderNotification</method>
25
+ </addedbytes_pushover>
26
+ </observers>
27
+ </sales_order_place_after>
28
+ <admin_system_config_changed_section_pushover>
29
+ <observers>
30
+ <addedbytes_pushover>
31
+ <class>addedbytespushover/observer</class>
32
+ <method>confirmConfiguration</method>
33
+ </addedbytes_pushover>
34
+ </observers>
35
+ </admin_system_config_changed_section_pushover>
36
+ </events>
37
+ </global>
38
+ <adminhtml>
39
+ <acl>
40
+ <resources>
41
+ <admin>
42
+ <children>
43
+ <system>
44
+ <children>
45
+ <config>
46
+ <children>
47
+ <pushover translate="title" module="addedbytes_pushover">
48
+ <title>Added Bytes Pushover</title>
49
+ <sort_order>0</sort_order>
50
+ </pushover>
51
+ </children>
52
+ </config>
53
+ </children>
54
+ </system>
55
+ </children>
56
+ </admin>
57
+ </resources>
58
+ </acl>
59
+ </adminhtml>
60
+ <default>
61
+ <pushover>
62
+ <pushover_options>
63
+ <pushover_active>0</pushover_active>
64
+ </pushover_options>
65
+ <!--<pushover_events>
66
+ <pushover_sales_order_place_after>1</pushover_sales_order_place_after>
67
+ <pushover_customer_register_success>0</pushover_customer_register_success>
68
+ </pushover_events>-->
69
+ </pushover>
70
+ </default>
71
+ </config>
app/code/local/Addedbytes/Pushover/etc/system.xml ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <addedbytes translate="label" module="addedbytes_pushover">
5
+ <label>Added Bytes</label>
6
+ <sort_order>90</sort_order>
7
+ </addedbytes>
8
+ </tabs>
9
+ <sections>
10
+ <pushover translate="label" module="addedbytes_pushover">
11
+ <label>Pushover</label>
12
+ <tab>addedbytes</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>25</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
+ <pushover_options translate="label">
20
+ <label>Options</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>0</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
+ <pushover_active translate="label">
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</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
+ </pushover_active>
36
+ </fields>
37
+ </pushover_options>
38
+ <pushover_settings translate="label">
39
+ <label>Pushover Settings</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>10</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>1</show_in_store>
45
+ <fields>
46
+ <pushover_api_token translate="label">
47
+ <label>Application API Token</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>0</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ <comment>
54
+ <![CDATA[Pushover application token. Register your app at <a target="_blank" href="https://pushover.net/apps/">https://pushover.net/apps/</a>. Please note free apps are limited to 7,500 notifications per month.]]>
55
+ </comment>
56
+ </pushover_api_token>
57
+ <pushover_user_keys translate="label">
58
+ <label>User Key(s)</label>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>10</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ <comment>
65
+ <![CDATA[Pushover user key to notify (if more than one, separate with commas).]]>
66
+ </comment>
67
+ </pushover_user_keys>
68
+ </fields>
69
+ </pushover_settings>
70
+ <!--<pushover_events translate="label">
71
+ <label>Pushover Events</label>
72
+ <frontend_type>text</frontend_type>
73
+ <sort_order>20</sort_order>
74
+ <show_in_default>1</show_in_default>
75
+ <show_in_website>1</show_in_website>
76
+ <show_in_store>1</show_in_store>
77
+ <fields>
78
+ <pushover_sales_order_place_after translate="label">
79
+ <label>New Order Placed</label>
80
+ <frontend_type>select</frontend_type>
81
+ <source_model>adminhtml/system_config_source_yesno</source_model>
82
+ <sort_order>10</sort_order>
83
+ <show_in_default>1</show_in_default>
84
+ <show_in_website>1</show_in_website>
85
+ <show_in_store>1</show_in_store>
86
+ </pushover_sales_order_place_after>
87
+ <pushover_customer_register_success translate="label">
88
+ <label>New Customer Registered</label>
89
+ <frontend_type>select</frontend_type>
90
+ <source_model>adminhtml/system_config_source_yesno</source_model>
91
+ <sort_order>10</sort_order>
92
+ <show_in_default>1</show_in_default>
93
+ <show_in_website>1</show_in_website>
94
+ <show_in_store>1</show_in_store>
95
+ </pushover_customer_register_success>
96
+ </fields>
97
+ </pushover_events>-->
98
+ </groups>
99
+ </pushover>
100
+ </sections>
101
+ </config>
app/etc/modules/Addedbytes_Pushover.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * This module sends notifications to your phone or other devices when orders
5
+ * are placed through Magento.
6
+ *
7
+ * By Added Bytes
8
+ * http://www.addedbytes.com
9
+ */
10
+ -->
11
+ <config>
12
+ <modules>
13
+ <Addedbytes_Pushover>
14
+ <active>true</active>
15
+ <codePool>local</codePool>
16
+ </Addedbytes_Pushover>
17
+ </modules>
18
+ </config>
package.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Addedbytes_Pushover</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Receive notifications of new orders on your mobile devices via Pushover.</summary>
10
+ <description> &lt;p&gt;This simple extension adds integration with the Pushover notification system to your Magento store.&lt;/p&gt;&#xD;
11
+ &#xD;
12
+ &lt;h3&gt;How Do I Use It?&lt;/h3&gt;&#xD;
13
+ &#xD;
14
+ &lt;p&gt;To install the extension:&lt;/p&gt;&#xD;
15
+ &#xD;
16
+ &lt;ul&gt;&#xD;
17
+ &lt;li&gt;Download the zip, and extract the contents&lt;/li&gt;&#xD;
18
+ &lt;li&gt;Upload the contents of the httpdocs folder to your website root folder&lt;/li&gt;&#xD;
19
+ &lt;li&gt;Clear Magento caches&lt;/li&gt;&#xD;
20
+ &lt;li&gt;Log out and log back in again&lt;/li&gt;&#xD;
21
+ &lt;li&gt;Go to System &amp;gt; Configuration &amp;gt; Added Bytes &amp;gt; Pushover and enter the appropriate credentials into the form.&lt;/li&gt;&#xD;
22
+ &lt;/ul&gt;&#xD;
23
+ &#xD;
24
+ &lt;h3&gt;How Do I Get Support?&lt;/h3&gt;&#xD;
25
+ &#xD;
26
+ &lt;p&gt;For technical or sales enquiries, please &lt;a href="mailto:support+pushover@addedbytes.com"&gt;email our support team&lt;/a&gt;.&lt;/p&gt;</description>
27
+ <notes>This release includes the base functionality. It allows you to link multiple Pushover accounts to your Magento stores and receive a notification whenever a new order is placed.</notes>
28
+ <authors><author><name>AddedBytes</name><user>AddedBytes</user><email>dave@addedbytes.com</email></author></authors>
29
+ <date>2015-09-02</date>
30
+ <time>20:01:38</time>
31
+ <contents><target name="magelocal"><dir name="Addedbytes"><dir name="Pushover"><dir name="Helper"><file name="Data.php" hash="d72220fac58c76840667fa67797322da"/></dir><dir name="Model"><file name="Observer.php" hash="4ff13a9670a3998c092cca8abae71683"/></dir><dir name="etc"><file name="config.xml" hash="f797aa0c319cdfa7d43a5d492a418020"/><file name="system.xml" hash="e9f614bc12e19523f3b95f8b2402fc04"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Addedbytes_Pushover.xml" hash="a04e8c2acde98e1d23e96299ad55ccee"/></dir></target></contents>
32
+ <compatible/>
33
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
34
+ </package>