aftership - Version 0.2.7

Version Notes

Support 1.7.0.2

Download this release

Release Info

Developer aftership
Extension aftership
Version 0.2.7
Comparing to
See all releases


Code changes from version 0.2.6 to 0.2.7

app/code/community/Aftership/Track/Model/Observer.php CHANGED
@@ -1,150 +1,169 @@
1
- <?php
2
-
3
- class Aftership_Track_Model_Observer
4
- {
5
- public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer)
6
- {
7
- ob_start();
8
- $config = Mage::getStoreConfig('aftership_options/messages');
9
-
10
- $track = $observer->getEvent()->getTrack();
11
- $track_data = $track->getData();
12
- $order_data = $track->getShipment()->getOrder()->getData();
13
- $shipment_data = $track->getShipment()->getData();
14
- $shipping_address_data = $track->getShipment()->getOrder()->getShippingAddress()->getData();
15
- if (strlen(trim($track_data["track_number"])) > 0) {
16
- //1.6.2.0 or later
17
- $track_no = trim($track_data["track_number"]);
18
- } else {
19
- //1.5.1.0
20
- $track_no = trim($track_data["number"]);
21
- }
22
-
23
- $exist_track_data = Mage::getModel('track/track')
24
- ->getCollection()
25
- ->addFieldToFilter('tracking_number', array('eq' => $track_no))
26
- ->addFieldToFilter('order_id', array('eq' => $order_data["order_id"]))
27
- ->getData();
28
-
29
-
30
- if (!$exist_track_data) {
31
- $track = Mage::getModel('track/track');
32
-
33
- $track->setTrackingNumber($track_no);
34
-
35
- $track->setShipCompCode($track_data["carrier_code"]);
36
- $track->setTitle($order_data["increment_id"]);
37
-
38
- $track->setOrderId($order_data["increment_id"]);
39
-
40
- if ($order_data["customer_email"] && $order_data["customer_email"] != "") {
41
- $track->setEmail($order_data["customer_email"]);
42
- }
43
-
44
- if ($shipping_address_data["telephone"] && $shipping_address_data["telephone"] != "") {
45
- $track->setTelephone($shipping_address_data["telephone"]);
46
- }
47
-
48
- if (array_key_exists("status", $config) && $config["status"]) {
49
- $track->setPosted(0);
50
- } else {
51
- $track->setPosted(2);
52
- }
53
-
54
- $track->save();
55
- }
56
-
57
-
58
- if (array_key_exists("status", $config) && $config["status"])
59
- {
60
- $api_key = $config["api_key"];
61
-
62
- $post_tracks = Mage::getModel('track/track')
63
- ->getCollection()
64
- ->addFieldToFilter('posted', array('eq' => 0))
65
- ->getData();
66
-
67
- $url_params = array("api_key" => $api_key);
68
-
69
- foreach ($post_tracks as $track) {
70
- $url = "https://api.aftership.com/v1/trackings";
71
- $url_params["tracking_number"] = $track["tracking_number"];
72
- $url_params["smses[]"] = $track["telephone"];
73
- $url_params["emails[]"] = $track["email"];
74
- $url_params["title"] = $track["title"];
75
- $url_params["order_id"] = $track["order_id"];
76
-
77
- $ch = curl_init();
78
- curl_setopt($ch, CURLOPT_URL, $url);
79
-
80
- curl_setopt($ch, CURLOPT_POST, true);
81
- curl_setopt($ch, CURLOPT_POSTFIELDS, $url_params);
82
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
83
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
84
- curl_setopt($ch, CURLOPT_HEADER, 0);
85
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
86
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //the SSL is not correct
87
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //the SSL is not correct
88
-
89
- $response = curl_exec($ch);
90
- $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
91
- $error = curl_error($ch);
92
- curl_close($ch);
93
- $response_obj = json_decode($response, true);
94
-
95
- if ($http_status == "201" || $http_status == "422") //422: repeated
96
- {
97
- $track_obj = Mage::getModel('track/track');
98
- $track_obj->load($track["track_id"]);
99
- $track_obj->setPosted(1);
100
- $track_obj->save();
101
- } else {
102
-
103
- }
104
- }
105
- }
106
-
107
- ob_end_clean();
108
- }
109
-
110
- public function adminSystemConfigChangedSectionAftership($obj)
111
- {
112
- $post_data = Mage::app()->getRequest()->getPost();
113
- $api_key = $post_data["groups"]["messages"]["fields"]["api_key"]["value"];
114
- if (!array_key_exists("notification", $post_data["groups"]["messages"]["fields"])) {
115
- Mage::getModel('core/config')->saveConfig('aftership_options/messages/notification', 0);
116
- }
117
-
118
- $url_params = array(
119
- "api_key" => $api_key
120
- );
121
- $url = "https://api.aftership.com/v1/users/authenticate";
122
-
123
- $ch = curl_init();
124
- curl_setopt($ch, CURLOPT_URL, $url);
125
- curl_setopt($ch, CURLOPT_POST, true);
126
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($url_params));
127
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
128
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
129
- curl_setopt($ch, CURLOPT_HEADER, 0);
130
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
131
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
132
-
133
- $response = curl_exec($ch);
134
- $error = curl_error($ch);
135
- $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
136
- curl_close($ch);
137
- $response_obj = json_decode($response, true);
138
-
139
- if ($http_status != "200" && $http_status != "401") {
140
- Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
141
- Mage::throwException(Mage::helper('adminhtml')->__("Connection error, please try again later."));
142
- } else {
143
- if (!$response_obj["success"]) //error
144
- {
145
- Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
146
- Mage::throwException(Mage::helper('adminhtml')->__("Incorrect API Key"));
147
- }
148
- }
149
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  }
1
+ <?php
2
+
3
+ class Aftership_Track_Model_Observer
4
+ {
5
+ public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer)
6
+ {
7
+ ob_start();
8
+ $config = Mage::getStoreConfig('aftership_options/messages');
9
+
10
+ $track = $observer->getEvent()->getTrack();
11
+ $track_data = $track->getData();
12
+ $order_data = $track->getShipment()->getOrder()->getData();
13
+ $shipment_data = $track->getShipment()->getData();
14
+ $shipping_address_data = $track->getShipment()->getOrder()->getShippingAddress()->getData();
15
+ if (strlen(trim($track_data["track_number"])) > 0) {
16
+ //1.6.2.0 or later
17
+ $track_no = trim($track_data["track_number"]);
18
+ } else {
19
+ //1.5.1.0
20
+ $track_no = trim($track_data["number"]);
21
+ }
22
+
23
+ $order_id = '';
24
+
25
+ if (isset($order_data["order_id"]))
26
+ {
27
+ $order_id = $order_data["order_id"];
28
+ }
29
+ else if (isset($order_data["increment_id"]))
30
+ {
31
+ $order_id = $order_data["increment_id"];
32
+ }
33
+
34
+ $exist_track_data = Mage::getModel('track/track')
35
+ ->getCollection()
36
+ ->addFieldToFilter('tracking_number', array('eq' => $track_no))
37
+ ->addFieldToFilter('order_id', array('eq' => $order_id))
38
+ ->getData();
39
+
40
+ if (!$exist_track_data) {
41
+ $track = Mage::getModel('track/track');
42
+
43
+ $track->setTrackingNumber($track_no);
44
+
45
+ $track->setShipCompCode($track_data["carrier_code"]);
46
+ $track->setTitle($order_data["increment_id"]);
47
+
48
+ $track->setOrderId($order_data["increment_id"]);
49
+
50
+ if ($order_data["customer_email"] && $order_data["customer_email"] != "") {
51
+ $track->setEmail($order_data["customer_email"]);
52
+ }
53
+
54
+ if ($shipping_address_data["telephone"] && $shipping_address_data["telephone"] != "") {
55
+ $track->setTelephone($shipping_address_data["telephone"]);
56
+ }
57
+
58
+ if (array_key_exists("status", $config) && $config["status"]) {
59
+ $track->setPosted(0);
60
+ } else {
61
+ $track->setPosted(2);
62
+ }
63
+
64
+ $track->save();
65
+ }
66
+
67
+
68
+ if (array_key_exists("status", $config) && $config["status"])
69
+ {
70
+ $api_key = $config["api_key"];
71
+
72
+ $post_tracks = Mage::getModel('track/track')
73
+ ->getCollection()
74
+ ->addFieldToFilter('posted', array('eq' => 0))
75
+ ->getData();
76
+
77
+ $url_params = array("api_key" => $api_key);
78
+
79
+ foreach ($post_tracks as $track) {
80
+
81
+ $url = "https://api.aftership.com/v1/trackings";
82
+ $url_params["tracking_number"] = $track["tracking_number"];
83
+ $url_params["smses[]"] = $track["telephone"];
84
+ $url_params["emails[]"] = $track["email"];
85
+ $url_params["title"] = $track["title"];
86
+ $url_params["order_id"] = $track["order_id"];
87
+ $url_params["customer_name"] = $shipping_address_data["firstname"]." ".$shipping_address_data['lastname'];
88
+ $url_params["source"] = "magento";
89
+
90
+
91
+ $ch = curl_init();
92
+ curl_setopt($ch, CURLOPT_URL, $url);
93
+ curl_setopt($ch, CURLOPT_POST, true);
94
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $url_params);
95
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
96
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
97
+ curl_setopt($ch, CURLOPT_HEADER, 0);
98
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
99
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //the SSL is not correct
100
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //the SSL is not correct
101
+
102
+ $response = curl_exec($ch);
103
+
104
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
105
+ $error = curl_error($ch);
106
+ curl_close($ch);
107
+ $response_obj = json_decode($response, true);
108
+
109
+ if ($http_status == "201" || $http_status == "422") //422: repeated
110
+ {
111
+ $track_obj = Mage::getModel('track/track');
112
+ $track_obj->load($track["track_id"]);
113
+ $track_obj->setPosted(1);
114
+ $track_obj->save();
115
+ }
116
+
117
+ //simulate track success post
118
+ /*$track_obj = Mage::getModel('track/track');
119
+ $track_obj->load($track["track_id"]);
120
+ $track_obj->setPosted(1);
121
+ $track_obj->save();*/
122
+
123
+ }
124
+ }
125
+
126
+ ob_end_clean();
127
+ }
128
+
129
+ public function adminSystemConfigChangedSectionAftership($obj)
130
+ {
131
+ $post_data = Mage::app()->getRequest()->getPost();
132
+ $api_key = $post_data["groups"]["messages"]["fields"]["api_key"]["value"];
133
+ if (!array_key_exists("notification", $post_data["groups"]["messages"]["fields"])) {
134
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/notification', 0);
135
+ }
136
+
137
+ $url_params = array(
138
+ "api_key" => $api_key
139
+ );
140
+ $url = "https://api.aftership.com/v1/users/authenticate";
141
+
142
+ $ch = curl_init();
143
+ curl_setopt($ch, CURLOPT_URL, $url);
144
+ curl_setopt($ch, CURLOPT_POST, true);
145
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($url_params));
146
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
147
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
148
+ curl_setopt($ch, CURLOPT_HEADER, 0);
149
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
150
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
151
+
152
+ $response = curl_exec($ch);
153
+ $error = curl_error($ch);
154
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
155
+ curl_close($ch);
156
+ $response_obj = json_decode($response, true);
157
+
158
+ if ($http_status != "200" && $http_status != "401") {
159
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
160
+ Mage::throwException(Mage::helper('adminhtml')->__("Connection error, please try again later."));
161
+ } else {
162
+ if (!$response_obj["success"]) //error
163
+ {
164
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
165
+ Mage::throwException(Mage::helper('adminhtml')->__("Incorrect API Key"));
166
+ }
167
+ }
168
+ }
169
  }
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>aftership</name>
4
- <version>0.2.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>AfterShip magento extension interface. Tracking number will be added to the aftership.com &lt;https://www.aftership.com/&gt; account at the same time when input in magento shipment. Please go to aftership.com &lt;https://www.aftership.com/&gt; to change the notification setting and value.</summary>
10
  <description>Users can simply link their online stores to Aftership and view all packages in one place. Online stores can also automatically inform their customers of the latest delivery status through SMS, email and Twitter. All the messages are white-labeled and can be customized for any marketing opportunities. Aftership also provides online stores a reporting tool so that they can easily find out any shipping problems like delayed delivery and solve immediately. Aftership currently supports over 40 shipping companies worldwide.</description>
11
- <notes>Changed PHP dependency version</notes>
12
  <authors><author><name>aftership</name><user>aftership</user><email>support@aftership.com</email></author></authors>
13
- <date>2012-12-18</date>
14
- <time>10:02:35</time>
15
- <contents><target name="magecommunity"><dir name="Aftership"><dir name="Track"><dir name="Helper"><file name="Data.php" hash="854baf793cb348f80c94703b585691b9"/></dir><dir name="Model"><file name="Methods.php" hash="ee6ccd73ab94405e8b0ab4a59990a0fa"/><dir name="Mysql4"><dir name="Track"><file name="Collection.php" hash="b359845af660063396556b37920675ad"/></dir><file name="Track.php" hash="e7799ea4fef0ff7e4217ae0d3a3ed50e"/></dir><file name="Observer.php" hash="87e8b2b2593e5e1b87fa8c282d7151f8"/><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="9a1fee597d5f7219cd3f68f38bb1ed97"/></dir></dir><file name="Track.php" hash="61bae429d01ace637296e11994203fe5"/><file name="Words.php" hash="40d412b8ea57998ae6429219b14709db"/></dir><dir name="controllers"><file name="IndexController.php" hash="7f5c1ae52f625152ca3e9ffe15a93028"/></dir><dir name="etc"><file name="config.xml" hash="1fef5c2ffa09abff28386c7f7979a399"/><file name="system.xml" hash="45dc0a90aa6f619006c7b930245e7879"/></dir><dir name="sql"><dir name="track_setup"><file name="mysql4-install-0.1.0.php" hash="6cfe686b1f1846396ff597956b99b692"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Aftership_Track.xml" hash="25367ce0ec0484973a73e5548199dea0"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.13</min><max>5.4.9</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>aftership</name>
4
+ <version>0.2.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>AfterShip magento extension interface. Tracking number will be added to the aftership.com &lt;https://www.aftership.com/&gt; account at the same time when input in magento shipment. Please go to aftership.com &lt;https://www.aftership.com/&gt; to change the notification setting and value.</summary>
10
  <description>Users can simply link their online stores to Aftership and view all packages in one place. Online stores can also automatically inform their customers of the latest delivery status through SMS, email and Twitter. All the messages are white-labeled and can be customized for any marketing opportunities. Aftership also provides online stores a reporting tool so that they can easily find out any shipping problems like delayed delivery and solve immediately. Aftership currently supports over 40 shipping companies worldwide.</description>
11
+ <notes>Support 1.7.0.2</notes>
12
  <authors><author><name>aftership</name><user>aftership</user><email>support@aftership.com</email></author></authors>
13
+ <date>2013-01-21</date>
14
+ <time>06:11:37</time>
15
+ <contents><target name="magecommunity"><dir name="Aftership"><dir name="Track"><dir name="Helper"><file name="Data.php" hash="854baf793cb348f80c94703b585691b9"/></dir><dir name="Model"><file name="Methods.php" hash="ee6ccd73ab94405e8b0ab4a59990a0fa"/><dir name="Mysql4"><dir name="Track"><file name="Collection.php" hash="b359845af660063396556b37920675ad"/></dir><file name="Track.php" hash="e7799ea4fef0ff7e4217ae0d3a3ed50e"/></dir><file name="Observer.php" hash="72b996e1e90688fe65a56594a9fa0700"/><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="9a1fee597d5f7219cd3f68f38bb1ed97"/></dir></dir><file name="Track.php" hash="61bae429d01ace637296e11994203fe5"/><file name="Words.php" hash="40d412b8ea57998ae6429219b14709db"/></dir><dir name="controllers"><file name="IndexController.php" hash="7f5c1ae52f625152ca3e9ffe15a93028"/></dir><dir name="etc"><file name="config.xml" hash="1fef5c2ffa09abff28386c7f7979a399"/><file name="system.xml" hash="45dc0a90aa6f619006c7b930245e7879"/></dir><dir name="sql"><dir name="track_setup"><file name="mysql4-install-0.1.0.php" hash="6cfe686b1f1846396ff597956b99b692"/></dir></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Aftership_Track.xml" hash="25367ce0ec0484973a73e5548199dea0"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.13</min><max>5.4.9</max></php></required></dependencies>
18
  </package>