clicksend - Version 1.0.0

Version Notes

ClickSend for Magento First Stable version

Download this release

Release Info

Developer ClickSend
Extension clicksend
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Clicksend/Sms/Helper/Data.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Clicksend_Sms_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function getVariables()
5
+ {
6
+ $variables = array();
7
+ $variables[] = '{ORDER-NUMBER}';
8
+ $variables[] = '{ORDER-TOTAL}';
9
+ $variables[] = '{ORDER-STATUS}';
10
+ $variables[] = '{CARRIER-NAME}';
11
+ $variables[] = '{PAYMENT-NAME}';
12
+ $variables[] = '{CUSTOMER-NAME}';
13
+ $variables[] = '{CUSTOMER-EMAIL}';
14
+ return $variables;
15
+ }
16
+ public function getIsClicksendSent($order_id)
17
+ {
18
+ $resource = Mage::getSingleton('core/resource');
19
+ $readConnection = $resource->getConnection('core_read');
20
+ $table = $resource->getTableName('sales_flat_order');
21
+
22
+ $query = "select is_clicksend_send from {$table} where entity_id = ".(int)($order_id);
23
+ return (int)($readConnection->fetchOne($query));
24
+ }
25
+ public function setIsClicksendSent($order_id)
26
+ {
27
+ $resource = Mage::getSingleton('core/resource');
28
+ $writeConnection = $resource->getConnection('core_write');
29
+ $table = $resource->getTableName('sales_flat_order');
30
+
31
+ $query = "update {$table} set is_clicksend_send=1 where entity_id = ".(int)($order_id);
32
+ $writeConnection->query($query);
33
+ }
34
+ public function getIncrementId($order)
35
+ {
36
+ $incrementId = $order->getOriginalIncrementId();
37
+ if($incrementId == null || empty($incrementId) || !$incrementId)
38
+ {
39
+ $incrementId = $order->getIncrementId();
40
+ }
41
+ return $incrementId;
42
+ }
43
+ public function getNewOrderMessage($order)
44
+ {
45
+ $variables = $this->getVariables();
46
+ $values = array();
47
+ $values[] = $this->getIncrementId($order);
48
+ $values[] = Mage::app()->getLocale()->currency($order->getOrderCurrencyCode())->toCurrency($order->getGrandTotal());
49
+ $values[] = $order->getStatus();
50
+ $values[] = $order->getShippingDescription();
51
+ $values[] = $order->getPayment()->getMethodInstance()->getTitle();
52
+ $values[] = $order->getCustomerFirstname().' '.$order->getCustomerLastname();
53
+ $values[] = $order->getCustomerEmail();
54
+ $message = Mage::getStoreConfig('clicksendsms/messages/sendsmsonnewordermessage');
55
+ return str_replace($variables, $values, $message);
56
+ }
57
+ public function getShippedStatusMessage($order)
58
+ {
59
+ $variables = $this->getVariables();
60
+ $values = array();
61
+ $values[] = $this->getIncrementId($order);
62
+ $values[] = Mage::app()->getLocale()->currency($order->getOrderCurrencyCode())->toCurrency($order->getGrandTotal());
63
+ $values[] = $order->getStatus();
64
+ $values[] = $order->getShippingDescription();
65
+ $values[] = $order->getPayment()->getMethodInstance()->getTitle();
66
+ $values[] = $order->getCustomerFirstname().' '.$order->getCustomerLastname();
67
+ $values[] = $order->getCustomerEmail();
68
+ $message = Mage::getStoreConfig('clicksendsms/messages/sendsmsonshipmessage');
69
+ return str_replace($variables, $values, $message);
70
+ }
71
+ public function sendSMS($to, $body, $action, $id_order, $countryCode)
72
+ {
73
+ try {
74
+ $source = 'magento';
75
+ $from = Mage::getStoreConfig('clicksendsms/settings/sender');
76
+ $username = Mage::getStoreConfig('clicksendsms/settings/username');
77
+ $password = Mage::getStoreConfig('clicksendsms/settings/password');
78
+ $data = array();
79
+ $message = array();
80
+ $message['source'] = $source;
81
+ $message['from'] = $from;
82
+ $message['body'] = $body;
83
+ $message['to'] = $to;
84
+ $message['country'] = $countryCode;
85
+ $data['messages'][] = $message;
86
+ $data = json_encode($data);
87
+ $this->log("{$id_order}-{$action}-Request");
88
+ $this->log($data);
89
+ $ch = curl_init();
90
+ curl_setopt($ch, CURLOPT_URL, "https://rest.clicksend.com/v3/sms/send");
91
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
92
+ curl_setopt($ch, CURLOPT_HEADER, false);
93
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
94
+ curl_setopt($ch, CURLOPT_POST, true);
95
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
96
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
97
+ "Content-Type: application/json",
98
+ "Content-Length: ".strlen($data),
99
+ "Authorization: Basic ".base64_encode($username.':'.$password)
100
+ ));
101
+ $response = curl_exec($ch);
102
+ if (!$response) {
103
+ throw new Exception(curl_error($ch));
104
+ }
105
+ curl_close($ch);
106
+ $this->log("{$id_order}-{$action}-Response");
107
+ $this->log($response);
108
+ } catch (Exception $e) {
109
+ $this->log("{$id_order}-{$action}-Response: ".$e->getMessage());
110
+ }
111
+ }
112
+ public function log($content)
113
+ {
114
+ if (Mage::getStoreConfig('clicksendsms/settings/debug')==1) {
115
+ Mage::log($content, null, 'clicksendsms.log', true);
116
+ }
117
+ }
118
+ }
app/code/local/Clicksend/Sms/Model/Observer.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Clicksend_Sms_Model_Observer
3
+ {
4
+ public function orderSave(Varien_Event_Observer $observer)
5
+ {
6
+ try {
7
+ $order = $observer->getOrder();
8
+ if ($order && $order->getId() > 0) {
9
+ if (Mage::helper('clicksendsms')->getIsClicksendSent($order->getId()) != 1) {
10
+ if (Mage::getStoreConfig('clicksendsms/messages/sendsmsonneworder') == 1) {
11
+ $countryCode = 'IN';Mage::getStoreConfig('general/country/default');
12
+ $body = Mage::helper('clicksendsms')->getNewOrderMessage($order);
13
+ $to = Mage::getStoreConfig('clicksendsms/settings/adminphone');
14
+ Mage::helper('clicksendsms')->sendSMS($to, $body, 'New_Order', $order->getId(), $countryCode);
15
+ Mage::helper('clicksendsms')->setIsClicksendSent($order->getId());
16
+ }
17
+ } elseif ($order->getOrigData('status') != $order->getStatus()) {
18
+ if ($order->hasShipments() && Mage::getStoreConfig('clicksendsms/messages/sendsmsonship') == 1) {
19
+ $address = $order->getShippingAddress();
20
+ if ($address) {
21
+ $countryCode = $address->getCountryId();
22
+ $to = $address->getTelephone();
23
+ } else {
24
+ $address = $order->getBillingAddress();
25
+ $countryCode = $address->getCountryId();
26
+ $to = $address->getTelephone();
27
+ }
28
+ $body = Mage::helper('clicksendsms')->getShippedStatusMessage($order);
29
+ Mage::helper('clicksendsms')->sendSMS($to, $body, 'Shipped_Status', $order->getId(), $countryCode);
30
+ }
31
+ }
32
+ }
33
+ } catch(Exception $e) {
34
+ Mage::log($order->getId().': Order Save, Exception:'.$e->getMessage(), null, 'clicksendsms.log', true);
35
+ }
36
+ }
37
+ }
app/code/local/Clicksend/Sms/etc/config.xml ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Clicksend_Sms>
5
+ <version>1.0.0</version>
6
+ </Clicksend_Sms>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <clicksendsms>
11
+ <class>Clicksend_Sms_Helper</class>
12
+ </clicksendsms>
13
+ </helpers>
14
+ <models>
15
+ <clicksendsms>
16
+ <class>Clicksend_Sms_Model</class>
17
+ </clicksendsms>
18
+ </models>
19
+ <resources>
20
+ <clicksendsms_setup>
21
+ <setup>
22
+ <module>Clicksend_Sms</module>
23
+ </setup>
24
+ <connection>
25
+ <use>core_setup</use>
26
+ </connection>
27
+ </clicksendsms_setup>
28
+ <clicksendsms_write>
29
+ <connection>
30
+ <use>core_write</use>
31
+ </connection>
32
+ </clicksendsms_write>
33
+ <clicksendsms_read>
34
+ <connection>
35
+ <use>core_read</use>
36
+ </connection>
37
+ </clicksendsms_read>
38
+ </resources>
39
+ <events>
40
+ <sales_order_save_after>
41
+ <observers>
42
+ <sales_order_save_after_clicksendsms>
43
+ <class>clicksendsms/observer</class>
44
+ <method>orderSave</method>
45
+ </sales_order_save_after_clicksendsms>
46
+ </observers>
47
+ </sales_order_save_after>
48
+ </events>
49
+ </global>
50
+ <adminhtml>
51
+ <menu>
52
+ <clicksendsms module="clicksendsms">
53
+ <title>ClickSend</title>
54
+ <sort_order>202</sort_order>
55
+ <children>
56
+ <admin module="clicksendsms">
57
+ <title>Configuration</title>
58
+ <sort_order>4</sort_order>
59
+ <action>adminhtml/system_config/edit/section/clicksendsms</action>
60
+ </admin>
61
+ </children>
62
+ </clicksendsms>
63
+ </menu>
64
+ <acl>
65
+ <resources>
66
+ <admin>
67
+ <children>
68
+ <system>
69
+ <children>
70
+ <config>
71
+ <children>
72
+ <clicksendsms>
73
+ <title>ClickSend</title>
74
+ </clicksendsms>
75
+ </children>
76
+ </config>
77
+ </children>
78
+ </system>
79
+ </children>
80
+ </admin>
81
+ </resources>
82
+ </acl>
83
+ </adminhtml>
84
+ </config>
app/code/local/Clicksend/Sms/etc/system.xml ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <clicksendsms translate="label" module="clicksendsms">
5
+ <label>ClickSend</label>
6
+ <sort_order>200</sort_order>
7
+ </clicksendsms>
8
+ </tabs>
9
+ <sections>
10
+ <clicksendsms translate="label" module="clicksendsms">
11
+ <label>Configuration</label>
12
+ <tab>clicksendsms</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>40</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
+ <settings translate="label">
20
+ <label>Settings</label>
21
+ <sort_order>1</sort_order>
22
+ <expanded>1</expanded>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>0</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <fields>
27
+ <username translate="label">
28
+ <label>ClickSend Username</label>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>1</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ <validate>required-entry</validate>
35
+ </username>
36
+ <password translate="label">
37
+ <label>ClickSend Password</label>
38
+ <frontend_type>password</frontend_type>
39
+ <sort_order>2</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ <validate>required-entry</validate>
44
+ </password>
45
+ <sender translate="label">
46
+ <label>Sender Number/Name</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
+ <validate>required-entry</validate>
53
+ </sender>
54
+ <adminphone translate="label">
55
+ <label>Admin Phone Number</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>4</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ <validate>required-entry</validate>
62
+ </adminphone>
63
+ <debug translate="label">
64
+ <label>Debug</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>5</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>0</show_in_store>
71
+ </debug>
72
+ </fields>
73
+ </settings>
74
+ <messages translate="label">
75
+ <label>Messages</label>
76
+ <sort_order>504</sort_order>
77
+ <expanded>2</expanded>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>0</show_in_website>
80
+ <show_in_store>0</show_in_store>
81
+ <fields>
82
+ <sendsmsonneworder translate="label">
83
+ <label>Send SMS to admin on 'New Order'</label>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_yesno</source_model>
86
+ <sort_order>1</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>0</show_in_store>
90
+ </sendsmsonneworder>
91
+ <sendsmsonnewordermessage translate="label">
92
+ <label>New Order Notification Message</label>
93
+ <frontend_type>textarea</frontend_type>
94
+ <sort_order>2</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <validate>required-entry</validate>
99
+ <depends><sendsmsonneworder>1</sendsmsonneworder></depends>
100
+ <tooltip><![CDATA[The following variables can be mixed with your message:<br/>{ORDER-NUMBER},{ORDER-TOTAL},{ORDER-STATUS},{CARRIER-NAME},{PAYMENT-NAME},{CUSTOMER-NAME}, and {CUSTOMER-EMAIL}]]></tooltip>
101
+ </sendsmsonnewordermessage>
102
+ <sendsmsonship translate="label">
103
+ <label>Send SMS to customer on status change to 'SHIPPED'</label>
104
+ <frontend_type>select</frontend_type>
105
+ <source_model>adminhtml/system_config_source_yesno</source_model>
106
+ <sort_order>3</sort_order>
107
+ <show_in_default>1</show_in_default>
108
+ <show_in_website>1</show_in_website>
109
+ <show_in_store>0</show_in_store>
110
+ </sendsmsonship>
111
+ <sendsmsonshipmessage translate="label">
112
+ <label>Status Change Notification Message</label>
113
+ <frontend_type>textarea</frontend_type>
114
+ <sort_order>4</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ <validate>required-entry</validate>
119
+ <depends><sendsmsonship>1</sendsmsonship></depends>
120
+ <tooltip><![CDATA[The following variables can be mixed with your message:<br/>{ORDER-NUMBER},{ORDER-TOTAL},{ORDER-STATUS},{CARRIER-NAME},{PAYMENT-NAME},{CUSTOMER-NAME}, and {CUSTOMER-EMAIL}]]></tooltip>
121
+ </sendsmsonshipmessage>
122
+ </fields>
123
+ </messages>
124
+ </groups>
125
+ </clicksendsms>
126
+ </sections>
127
+ </config>
app/code/local/Clicksend/Sms/sql/clicksendsms_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $installer->run("ALTER TABLE `".$this->getTable('sales_flat_order')."` ADD is_clicksend_send tinyint(1)");
6
+
7
+ $installer->endSetup();
8
+ ?>
app/etc/modules/Clicksend_Sms.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Clicksend_Sms>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Clicksend_Sms>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ClickSend</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>ClickSend for Magento</summary>
10
+ <description>ClickSend for Magento</description>
11
+ <notes>ClickSend for Magento First Stable version</notes>
12
+ <authors><author><name>ClickSend</name><user>ClickSend</user><email>ClickSend@gmail.com</email></author></authors>
13
+ <date>2016-05-30</date>
14
+ <time>04:55:48</time>
15
+ <contents><target name="magelocal"><dir name="Clicksend"><dir name="Sms"><dir name="Helper"><file name="Data.php" hash="773942d7f772c3ab67831c2c48f08236"/></dir><dir name="Model"><file name="Observer.php" hash="c7c4460020c2cad8f3ba83ffcd891e64"/></dir><dir name="etc"><file name="config.xml" hash="5877e43e7bd88fcd94271ad6f0cc778c"/><file name="system.xml" hash="9380377b8bf9f88734e2edca3a942f9b"/></dir><dir name="sql"><dir name="clicksendsms_setup"><file name="mysql4-install-1.0.0.php" hash="d89c2614dc951f24170cb1f1e304440b"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Clicksend_Sms.xml" hash="ec743a5ae15ae7eb8cc766bd90ed26e0"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>7.0.0</max></php></required></dependencies>
18
+ </package>