Smsapi_Sms - Version 0.1.2

Version Notes

Fix no sms at status "complete".

Download this release

Release Info

Developer SMSAPI
Extension Smsapi_Sms
Version 0.1.2
Comparing to
See all releases


Code changes from version 0.1.1 to 0.1.2

app/code/community/Smsapi/Sms/Model/Observer.php CHANGED
@@ -18,89 +18,84 @@ class Smsapi_Sms_Model_Observer {
18
  */
19
 
20
  public function handleStatus($observer) {
21
-
22
  $config = Mage::getModel('sms/config');
23
- if ($config->isApiEnabled()==0) return; //do nothing if api is disabled
24
-
 
25
  $order = $observer->getEvent()->getOrder();
26
-
 
 
27
 
28
- $newStatus = $order->getData('status');
29
- $origStatus = $order->getOrigData('status');
30
-
31
-
32
- //if status has changed run action
33
- if ($newStatus!=$origStatus) {
34
-
35
- $message = $config->getMessageTemplate($newStatus); //get template for new status (if active and exists)
36
- if (!$message) //return if no active message template
37
- return;
38
 
39
-
40
- //getting last tracking number
41
- $trackings = Mage::getResourceModel('sales/order_shipment_track_collection')->setOrderFilter($order)->getData();
42
-
43
- if (!empty($trackings)) {
44
- $last = count($trackings)-1;
45
- $last_tracking_number = $trackings[$last]['track_number'];
46
- }
47
- else
48
- $last_tracking_number = 'no_tracking'; //if no tracking number set "no_tracking" message for {TRACKINGNUMBER} template
49
-
50
-
51
- $address = $order->getShippingAddress();
52
- if (!$address)
53
- $address = $order->getBillingAddress();
54
-
55
-
56
- try { //try to send message
57
-
58
-
59
- //getting order data to generate message template
60
- $messageOrderData['{NAME}'] = $address->getData('firstname');
61
- $messageOrderData['{ORDERNUMBER}'] = $order->getIncrement_id();
62
- $messageOrderData['{ORDERSTATUS}'] = $newStatus;
63
- $messageOrderData['{TRACKINGNUMBER}'] = $last_tracking_number;
64
- $messageOrderData['{STORENAME}'] = $config->getApiStoreName();
65
-
66
- $message = strtr($message,$messageOrderData);
67
-
68
-
69
-
70
- $api = Mage::getModel('sms/apiClient');
71
- $api->connect();
72
-
73
- //prepare sms content
74
- $msg['recipient'] = $address->getData('telephone'); //or getBillingAddress
75
- $msg['message'] = $message;
76
- $msg['eco'] = $config->isEco(); //eco version - without sender
77
- $msg['test'] = $config->testMode();
78
- $msg['single_message'] = $config->isSingle(); //allow_long_sms
79
- $msg['sender'] = $config->getSender();//sender
80
-
81
-
82
- //sending sms and getting API response
83
-
84
- try {
85
-
86
- $response = $api->msgContent($msg)->send();
87
- $newComment = Mage::helper('sms')->__('SMS notification sent (SMS id:').$response->response[0]->id.') ' ;
88
- $order->addStatusToHistory($order->getStatus(),$newComment,true);
89
-
90
-
91
- } catch (Exception $e) {
92
- $newComment = Mage::helper('sms')->__('SMS notification sending error: "').$e->getMessage().'"';
93
- $order->addStatusToHistory($order->getStatus(),$newComment,false);
94
- }
95
-
96
- $this->checkPointsLimit(); //check
97
-
98
-
99
- } catch ( Exception $e ) {
100
- Mage::log('exception'.$e->getMessage());
101
- }
102
-
103
- }
104
 
105
  }
106
 
18
  */
19
 
20
  public function handleStatus($observer) {
21
+
22
  $config = Mage::getModel('sms/config');
23
+ if ($config->isApiEnabled()==0)
24
+ return; //do nothing if api is disabled
25
+
26
  $order = $observer->getEvent()->getOrder();
27
+ $newStatus = $order->getStatus();
28
+ if (Mage::registry($newStatus.'_executed') == true)
29
+ return;
30
 
31
+ Mage::register($newStatus.'_executed', true);
32
+ $message = $config->getMessageTemplate($newStatus); //get template for new status (if active and exists)
33
+ if (!$message) //return if no active message template
34
+ return;
 
 
 
 
 
 
35
 
36
+
37
+ //getting last tracking number
38
+ $trackings = Mage::getResourceModel('sales/order_shipment_track_collection')->setOrderFilter($order)->getData();
39
+
40
+ if (!empty($trackings)) {
41
+ $last = count($trackings)-1;
42
+ $last_tracking_number = $trackings[$last]['track_number'];
43
+ }
44
+ else
45
+ $last_tracking_number = 'no_tracking'; //if no tracking number set "no_tracking" message for {TRACKINGNUMBER} template
46
+
47
+
48
+ $address = $order->getShippingAddress();
49
+ if (!$address)
50
+ $address = $order->getBillingAddress();
51
+
52
+
53
+ try { //try to send message
54
+
55
+
56
+ //getting order data to generate message template
57
+ $messageOrderData['{NAME}'] = $address->getData('firstname');
58
+ $messageOrderData['{ORDERNUMBER}'] = $order->getIncrement_id();
59
+ $messageOrderData['{ORDERSTATUS}'] = $newStatus;
60
+ $messageOrderData['{TRACKINGNUMBER}'] = $last_tracking_number;
61
+ $messageOrderData['{STORENAME}'] = $config->getApiStoreName();
62
+
63
+ $message = strtr($message,$messageOrderData);
64
+
65
+
66
+
67
+ $api = Mage::getModel('sms/apiClient');
68
+ $api->connect();
69
+
70
+ //prepare sms content
71
+ $msg['recipient'] = $address->getData('telephone'); //or getBillingAddress
72
+ $msg['message'] = $message;
73
+ $msg['eco'] = $config->isEco(); //eco version - without sender
74
+ $msg['test'] = $config->testMode();
75
+ $msg['single_message'] = $config->isSingle(); //allow_long_sms
76
+ $msg['sender'] = $config->getSender();//sender
77
+
78
+
79
+ //sending sms and getting API response
80
+
81
+ try {
82
+
83
+ $response = $api->msgContent($msg)->send();
84
+ $newComment = Mage::helper('sms')->__('SMS notification sent (SMS id:').$response->response[0]->id.') ' ;
85
+ $order->addStatusToHistory($newStatus,$newComment,true);
86
+
87
+
88
+ } catch (Exception $e) {
89
+ $newComment = Mage::helper('sms')->__('SMS notification sending error: "').$e->getMessage().'"';
90
+ $order->addStatusToHistory($newStatus,$newComment,false);
91
+ }
92
+
93
+ $this->checkPointsLimit(); //check
94
+
95
+
96
+ } catch ( Exception $e ) {
97
+ Mage::log('exception'.$e->getMessage());
98
+ }
 
 
99
 
100
  }
101
 
app/code/community/Smsapi/Sms/etc/config.xml CHANGED
@@ -35,7 +35,7 @@
35
 
36
  <modules>
37
  <Smsapi_Sms>
38
- <version>0.1.1</version>
39
  </Smsapi_Sms>
40
  </modules>
41
 
@@ -50,16 +50,16 @@
50
  <class>Smsapi_Sms_Model</class>
51
  </sms>
52
  </models>
53
- <events>
54
- <sales_order_save_before>
55
- <observers>
56
- <order_new_status>
57
- <class>Smsapi_Sms_Model_Observer</class>
58
- <method>handleStatus</method>
59
- </order_new_status>
60
- </observers>
61
- </sales_order_save_before>
62
- </events>
63
  <blocks>
64
  <sms>
65
  <class>Smsapi_Sms_Block</class>
35
 
36
  <modules>
37
  <Smsapi_Sms>
38
+ <version>0.1.2</version>
39
  </Smsapi_Sms>
40
  </modules>
41
 
50
  <class>Smsapi_Sms_Model</class>
51
  </sms>
52
  </models>
53
+ <events>
54
+ <sales_order_save_commit_after>
55
+ <observers>
56
+ <smsapi_sms>
57
+ <class>Smsapi_Sms_Model_Observer</class>
58
+ <method>handleStatus</method>
59
+ </smsapi_sms>
60
+ </observers>
61
+ </sales_order_save_commit_after>
62
+ </events>
63
  <blocks>
64
  <sms>
65
  <class>Smsapi_Sms_Block</class>
app/code/community/Smsapi/Sms/etc/system.xml CHANGED
@@ -91,7 +91,7 @@
91
  <show_in_website>1</show_in_website>
92
  <show_in_store>1</show_in_store>
93
  </apipassword>
94
-
95
  <storename translate="label">
96
  <label>Store name</label>
97
  <frontend_type>text</frontend_type>
@@ -100,7 +100,7 @@
100
  <show_in_website>1</show_in_website>
101
  <show_in_store>1</show_in_store>
102
  </storename>
103
-
104
  <sender translate="label comment">
105
  <label>SMS Sender</label>
106
  <frontend_type>select</frontend_type>
@@ -111,7 +111,7 @@
111
  <show_in_store>1</show_in_store>
112
  <comment>To add new SMS Sender go to "http://www.sms.pl" -> (left menu) USTAWIENIA -> POLA NADAWCY</comment>
113
  </sender>
114
-
115
  <allow_long_sms translate="label">
116
  <label>Allow long messages (more than 160 chars)</label>
117
  <frontend_type>select</frontend_type>
@@ -121,7 +121,7 @@
121
  <show_in_website>1</show_in_website>
122
  <show_in_store>1</show_in_store>
123
  </allow_long_sms>
124
-
125
  <points_alert_limit translate="label comment">
126
  <label>Notify if my SMSAPI account points is below:</label>
127
  <comment>0 - turn off/no alert</comment>
@@ -134,7 +134,7 @@
134
  </points_alert_limit>
135
  </fields>
136
  </main_conf>
137
-
138
  <templates translate="label comment" module="sms">
139
  <label>Message templates</label>
140
  <frontend_type>text</frontend_type>
@@ -145,7 +145,7 @@
145
  <show_in_store>1</show_in_store>
146
  <expanded>1</expanded>
147
  <fields>
148
-
149
  <status_pending_payment_active translate="label">
150
  <label>Send SMS after status changed to "Pending Payment"</label>
151
  <frontend_type>select</frontend_type>
@@ -164,7 +164,7 @@
164
  <show_in_store>1</show_in_store>
165
  <depends><status_pending_payment_active>1</status_pending_payment_active></depends>
166
  </status_pending_payment>
167
-
168
  <status_holded_active translate="label">
169
  <label>Send SMS after status changed to "On Hold"</label>
170
  <frontend_type>select</frontend_type>
@@ -182,8 +182,8 @@
182
  <show_in_website>1</show_in_website>
183
  <show_in_store>1</show_in_store>
184
  <depends><status_holded_active>1</status_holded_active></depends>
185
- </status_holded>
186
-
187
  <status_processing_active translate="label">
188
  <label>Send SMS after status changed to "Processing"</label>
189
  <frontend_type>select</frontend_type>
@@ -202,7 +202,7 @@
202
  <show_in_store>1</show_in_store>
203
  <depends><status_processing_active>1</status_processing_active></depends>
204
  </status_processing>
205
-
206
  <status_canceled_active translate="label">
207
  <label>Send SMS after status changed to "Canceled"</label>
208
  <frontend_type>select</frontend_type>
@@ -221,7 +221,7 @@
221
  <show_in_store>1</show_in_store>
222
  <depends><status_canceled_active>1</status_canceled_active></depends>
223
  </status_canceled>
224
-
225
  <status_complete_active translate="label">
226
  <label>Send SMS after status changed to "Complete"</label>
227
  <frontend_type>select</frontend_type>
@@ -240,7 +240,7 @@
240
  <show_in_store>1</show_in_store>
241
  <depends><status_complete_active>1</status_complete_active></depends>
242
  </status_complete>
243
-
244
  <status_closed_active translate="label">
245
  <label>Send SMS after status changed to "Closed"</label>
246
  <frontend_type>select</frontend_type>
@@ -261,7 +261,7 @@
261
  </status_closed>
262
  </fields>
263
  </templates>
264
-
265
  <admin_mode translate="label" module="sms">
266
  <label>Test configuration</label>
267
  <frontend_type>text</frontend_type>
91
  <show_in_website>1</show_in_website>
92
  <show_in_store>1</show_in_store>
93
  </apipassword>
94
+
95
  <storename translate="label">
96
  <label>Store name</label>
97
  <frontend_type>text</frontend_type>
100
  <show_in_website>1</show_in_website>
101
  <show_in_store>1</show_in_store>
102
  </storename>
103
+
104
  <sender translate="label comment">
105
  <label>SMS Sender</label>
106
  <frontend_type>select</frontend_type>
111
  <show_in_store>1</show_in_store>
112
  <comment>To add new SMS Sender go to "http://www.sms.pl" -> (left menu) USTAWIENIA -> POLA NADAWCY</comment>
113
  </sender>
114
+
115
  <allow_long_sms translate="label">
116
  <label>Allow long messages (more than 160 chars)</label>
117
  <frontend_type>select</frontend_type>
121
  <show_in_website>1</show_in_website>
122
  <show_in_store>1</show_in_store>
123
  </allow_long_sms>
124
+
125
  <points_alert_limit translate="label comment">
126
  <label>Notify if my SMSAPI account points is below:</label>
127
  <comment>0 - turn off/no alert</comment>
134
  </points_alert_limit>
135
  </fields>
136
  </main_conf>
137
+
138
  <templates translate="label comment" module="sms">
139
  <label>Message templates</label>
140
  <frontend_type>text</frontend_type>
145
  <show_in_store>1</show_in_store>
146
  <expanded>1</expanded>
147
  <fields>
148
+
149
  <status_pending_payment_active translate="label">
150
  <label>Send SMS after status changed to "Pending Payment"</label>
151
  <frontend_type>select</frontend_type>
164
  <show_in_store>1</show_in_store>
165
  <depends><status_pending_payment_active>1</status_pending_payment_active></depends>
166
  </status_pending_payment>
167
+
168
  <status_holded_active translate="label">
169
  <label>Send SMS after status changed to "On Hold"</label>
170
  <frontend_type>select</frontend_type>
182
  <show_in_website>1</show_in_website>
183
  <show_in_store>1</show_in_store>
184
  <depends><status_holded_active>1</status_holded_active></depends>
185
+ </status_holded>
186
+
187
  <status_processing_active translate="label">
188
  <label>Send SMS after status changed to "Processing"</label>
189
  <frontend_type>select</frontend_type>
202
  <show_in_store>1</show_in_store>
203
  <depends><status_processing_active>1</status_processing_active></depends>
204
  </status_processing>
205
+
206
  <status_canceled_active translate="label">
207
  <label>Send SMS after status changed to "Canceled"</label>
208
  <frontend_type>select</frontend_type>
221
  <show_in_store>1</show_in_store>
222
  <depends><status_canceled_active>1</status_canceled_active></depends>
223
  </status_canceled>
224
+
225
  <status_complete_active translate="label">
226
  <label>Send SMS after status changed to "Complete"</label>
227
  <frontend_type>select</frontend_type>
240
  <show_in_store>1</show_in_store>
241
  <depends><status_complete_active>1</status_complete_active></depends>
242
  </status_complete>
243
+
244
  <status_closed_active translate="label">
245
  <label>Send SMS after status changed to "Closed"</label>
246
  <frontend_type>select</frontend_type>
261
  </status_closed>
262
  </fields>
263
  </templates>
264
+
265
  <admin_mode translate="label" module="sms">
266
  <label>Test configuration</label>
267
  <frontend_type>text</frontend_type>
package.xml CHANGED
@@ -1,19 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Smsapi_Sms</name>
4
- <version>0.1.1</version>
5
  <stability>stable</stability>
6
- <license>SMSAPI licence</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>SMSAPI Module for Magento-based stores enables automatic send SMS notifications to customers.</summary>
10
- <description>SMSAPI Module for Magento-based stores enables automatic send SMS notifications to customers. SMS communication has many benefits including facilitates communication with your customers and speeds up reaching the details of the order. Short text messages are sent primarily as information on the status of the order, such as a message confirming the correct course of a transaction or message about delivery time of orders . SMS is fastest communication with your customers, and savings for the company due to reduced costs associated with undelivered shipments. SMS notifications in Magento module can be sent from the field in active sender SMSAPI account. Content templates are fully editable.</description>
11
- <notes>SMSAPI SMS v 0.1.1&#xD;
12
- Some little fixes.</notes>
13
- <authors><author><name>Marek Jasiukiewicz</name><user>jasiukiewicz_m</user><email>dev@jasiukiewicz.pl</email></author><author><name>Snowdog</name><user>snowdog</user><email>support@snowdog.pl</email></author><author><name>SMSAPI</name><user>smsapi</user><email>info@smsapi.pl</email></author></authors>
14
- <date>2013-03-22</date>
15
- <time>11:22:03</time>
16
- <contents><target name="magecommunity"><dir name="Smsapi"><dir name="Sms"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Branding.php" hash="849bdf4e1e79bc1e83a871a5d92d69b4"/></dir></dir></dir></dir><file name="Buttons.php" hash="9c3419026c5a9e89ccd6d0203faeee51"/></dir><dir name="Helper"><file name="Data.php" hash="c9f5c5eda233f035bf8d44d5bdf040ea"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="daec22c1bf38a90c4cce45a264f82516"/></dir><file name="ApiClient.php" hash="74ab753538d8effa2d837ac50ebb9b40"/><file name="Config.php" hash="e19170fc3519ba96493770096f730ba0"/><file name="Observer.php" hash="539eff3f0c1c24ec3ebdd92a829329c9"/></dir><dir name="etc"><file name="config.xml" hash="b3723affae72c61b68b850a0b5a4cee4"/><file name="system.xml" hash="7639904e60d72ed0e4c9db9c7f08f2f3"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="layout"><file name="Smsapi_Sms.xml" hash="93d7067aa579e4c268b0174164e9f4ff"/></dir><dir name="template"><dir name="sms"><dir name="system"><dir name="config"><dir name="fieldset"><file name="branding.phtml" hash="5e4de796726e17f8230cd51cbf535fd7"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Smsapi_Sms.xml" hash="4e65007f9573a00788a27745861bcaab"/></dir></target><target name="mage"><dir name="js"><dir name="smsapi"><dir name="sms"><file name="counter.js" hash="5ff48e9e8c365324e76526cf160b0c39"/></dir></dir></dir></target><target name="magelocale"><dir name="pl_PL"><file name="Smsapi_Sms.csv" hash="a3995f33f97ea887767c5403aea9ad56"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="images"><dir name="smsapi"><dir name="sms"><file name="smsapi_logo.jpg" hash="8fe4a8d39c915d9e5d138cadf4a3fca4"/></dir></dir></dir></dir></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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Smsapi_Sms</name>
4
+ <version>0.1.2</version>
5
  <stability>stable</stability>
6
+ <license>OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>SMS Module for Magento enables automatic sending SMS notifications.</summary>
10
+ <description>SMSAPI Module for Magento-based stores enables automatic send SMS notifications to customers. SMS communication has many benefits including facilitates communication with your customers and speeds up reaching the details of the order. Short text messages are sent primarily as information on the status of the order, such as a message confirming the correct course of a transaction or message about delivery time of orders. SMS is fastest communication with your customers, and savings for the company due to reduced costs associated with undelivered shipments. SMS notifications in Magento module can be sent from the field in active sender SMSAPI account. Content templates are fully editable. More info</description>
11
+ <notes>Fix no sms at status "complete".</notes>
12
+ <authors><author><name>SMSAPI</name><user>smsapi</user><email>info@smsapi.pl</email></author><author><name>Snowdog</name><user>snowdog</user><email>support@snowdog.pl</email></author><author><name>Marek Jasiukiewicz</name><user>jasiukiewicz_m</user><email>dev@jasiukiewicz.pl</email></author></authors>
13
+ <date>2013-10-25</date>
14
+ <time>10:38:12</time>
15
+ <contents><target name="magecommunity"><dir name="Smsapi"><dir name="Sms"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Branding.php" hash="849bdf4e1e79bc1e83a871a5d92d69b4"/></dir></dir></dir></dir><file name="Buttons.php" hash="9c3419026c5a9e89ccd6d0203faeee51"/></dir><dir name="Helper"><file name="Data.php" hash="c9f5c5eda233f035bf8d44d5bdf040ea"/></dir><dir name="Model"><dir name="Adminhtml"><file name="Attributes.php" hash="daec22c1bf38a90c4cce45a264f82516"/></dir><file name="ApiClient.php" hash="74ab753538d8effa2d837ac50ebb9b40"/><file name="Config.php" hash="e19170fc3519ba96493770096f730ba0"/><file name="Observer.php" hash="e02a40782b4436da13e856301ad7ffe1"/></dir><dir name="etc"><file name="config.xml" hash="3922e99ae84aa512c18feb9a0e05c790"/><file name="system.xml" hash="4f459eeb8cd53e9195c549fcb667ef4d"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="layout"><file name="Smsapi_Sms.xml" hash="93d7067aa579e4c268b0174164e9f4ff"/></dir><dir name="template"><dir name="sms"><dir name="system"><dir name="config"><dir name="fieldset"><file name="branding.phtml" hash="5e4de796726e17f8230cd51cbf535fd7"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Smsapi_Sms.xml" hash="4e65007f9573a00788a27745861bcaab"/></dir></target><target name="magelocale"><dir name="pl_PL"><file name="Smsapi_Sms.csv" hash="a3995f33f97ea887767c5403aea9ad56"/></dir></target><target name="mage"><dir name="js"><dir name="smsapi"><dir name="sms"><file name="counter.js" hash="5ff48e9e8c365324e76526cf160b0c39"/></dir></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="images"><dir name="smsapi"><dir name="sms"><file name="smsapi_logo.jpg" hash="8fe4a8d39c915d9e5d138cadf4a3fca4"/></dir></dir></dir></dir></dir></dir></target></contents>
 
16
  <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>