aftership - Version 0.2.2

Version Notes

Bug fixes

Download this release

Release Info

Developer aftership
Extension aftership
Version 0.2.2
Comparing to
See all releases


Code changes from version 0.2.1 to 0.2.2

app/code/community/Aftership/.DS_Store ADDED
Binary file
app/code/community/Aftership/Track/.DS_Store ADDED
Binary file
app/code/community/Aftership/Track/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ }
5
+ ?>
app/code/community/Aftership/Track/Model/Methods.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Methods
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>1, 'label'=>Mage::helper('aftership')->__('Email')),
8
+ array('value'=>2, 'label'=>Mage::helper('aftership')->__('SMS')),
9
+ );
10
+ }
11
+
12
+ }
13
+ ?>
app/code/community/Aftership/Track/Model/Mysql4/Track.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Mysql4_Track extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('track/track','track_id');
7
+ }
8
+ }
9
+ ?>
app/code/community/Aftership/Track/Model/Mysql4/Track/Collection.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Mysql4_Track_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('track/track');
7
+ }
8
+ }
9
+ ?>
app/code/community/Aftership/Track/Model/Observer.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /*if(array_key_exists("notification",$config)){
11
+ $notifications = explode(",",$config["notification"]);
12
+ if(array_search("1",$notifications)!==False){ // email
13
+ $is_notify_email = true;
14
+ }else{
15
+ $is_notify_email = false;
16
+ }
17
+ if(array_search("2",$notifications)!==False){ // sms
18
+ $is_notify_sms = true;
19
+ }else{
20
+ $is_notify_sms = false;
21
+ }
22
+ }else{
23
+ $is_notify_email = false;
24
+ $is_notify_sms = false;
25
+ }*/
26
+
27
+ $track = $observer->getEvent()->getTrack();
28
+ $track_data = $track->getData();
29
+ $order_data = $track->getShipment()->getOrder()->getData();
30
+ $shipment_data = $track->getShipment()->getData();
31
+ $shipping_address_data = $track->getShipment()->getOrder()->getShippingAddress()->getData();
32
+ if (strlen(trim($track_data["track_number"])) > 0) {
33
+ //1.6.2.0 or later
34
+ $track_no = trim($track_data["track_number"]);
35
+ } else {
36
+ //1.5.1.0
37
+ $track_no = trim($track_data["number"]);
38
+ }
39
+
40
+ $exist_track_data = Mage::getModel('track/track')
41
+ ->getCollection()
42
+ ->addFieldToFilter('tracking_number', array('eq' => $track_no))
43
+ ->addFieldToFilter('order_id', array('eq' => $order_data["order_id"]))
44
+ ->getData();
45
+
46
+
47
+ if (!$exist_track_data) {
48
+ $track = Mage::getModel('track/track');
49
+
50
+ $track->setTrackingNumber($track_no);
51
+
52
+ $track->setShipCompCode($track_data["carrier_code"]);
53
+ //$track->setTitle($_SERVER['HTTP_HOST'] . " " . $order_data["increment_id"]);
54
+ //$track->setTitle($_SERVER['HTTP_ORIGIN'] . " " . $order_data["increment_id"]);
55
+ $track->setTitle($order_data["increment_id"]);
56
+
57
+ $track->setOrderId($order_data["increment_id"]);
58
+
59
+ if ($order_data["customer_email"] && $order_data["customer_email"] != "") {
60
+ $track->setEmail($order_data["customer_email"]);
61
+ }
62
+
63
+ if ($shipping_address_data["telephone"] && $shipping_address_data["telephone"] != "") {
64
+ $track->setTelephone($shipping_address_data["telephone"]);
65
+ }
66
+
67
+ /*
68
+ if($is_notify_email){
69
+ $track->setEmail($order_data["customer_email"]);
70
+ }
71
+
72
+ if($is_notify_sms){
73
+ $track->setTelephone($shipping_address_data["telephone"]);
74
+ }*/
75
+
76
+
77
+ if (array_key_exists("status", $config) && $config["status"]) {
78
+ $track->setPosted(0);
79
+ } else {
80
+ $track->setPosted(2);
81
+ }
82
+
83
+ $track->save();
84
+ }
85
+
86
+
87
+ if (array_key_exists("status", $config) && $config["status"])
88
+ {
89
+ $api_key = $config["api_key"];
90
+
91
+ $post_tracks = Mage::getModel('track/track')
92
+ ->getCollection()
93
+ ->addFieldToFilter('posted', array('eq' => 0))
94
+ ->getData();
95
+
96
+ $url_params = array("api_key" => $api_key);
97
+
98
+ foreach ($post_tracks as $track) {
99
+ $url = "https://api.aftership.com/v1/trackings";
100
+ $url_params["tracking_number"] = $track["tracking_number"];
101
+ $url_params["smses"] = array($track["telephone"]);
102
+ $url_params["emails"] = array($track["email"]);
103
+ $url_params["title"] = $track["title"];
104
+ $url_params["order_id"] = $track["order_id"];
105
+
106
+ $ch = curl_init();
107
+ curl_setopt($ch, CURLOPT_URL, $url);
108
+
109
+ curl_setopt($ch, CURLOPT_POST, true);
110
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $url_params);
111
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
112
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
113
+ curl_setopt($ch, CURLOPT_HEADER, 0);
114
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
115
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //the SSL is not correct
116
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //the SSL is not correct
117
+
118
+ $response = curl_exec($ch);
119
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
120
+ $error = curl_error($ch);
121
+ curl_close($ch);
122
+ $response_obj = json_decode($response, true);
123
+
124
+ if ($http_status == "201" || $http_status == "422") //422: repeated
125
+ {
126
+ $track_obj = Mage::getModel('track/track');
127
+ $track_obj->load($track["track_id"]);
128
+ $track_obj->setPosted(1);
129
+ $track_obj->save();
130
+ } else {
131
+
132
+ }
133
+ }
134
+ }
135
+
136
+ ob_end_clean();
137
+ }
138
+
139
+ public function adminSystemConfigChangedSectionAftership($obj)
140
+ {
141
+ $post_data = Mage::app()->getRequest()->getPost();
142
+ $api_key = $post_data["groups"]["messages"]["fields"]["api_key"]["value"];
143
+ if (!array_key_exists("notification", $post_data["groups"]["messages"]["fields"])) {
144
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/notification', 0);
145
+ }
146
+
147
+ $url_params = array(
148
+ "api_key" => $api_key
149
+ );
150
+ $url = "http://api.aftership.com/v1/users/authenticate";
151
+
152
+ $ch = curl_init();
153
+ curl_setopt($ch, CURLOPT_URL, $url);
154
+ curl_setopt($ch, CURLOPT_POST, true);
155
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($url_params));
156
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
157
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
158
+ curl_setopt($ch, CURLOPT_HEADER, 0);
159
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
160
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
161
+
162
+ $response = curl_exec($ch);
163
+ $error = curl_error($ch);
164
+ $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
165
+ curl_close($ch);
166
+ $response_obj = json_decode($response, true);
167
+
168
+ if ($http_status != "200" && $http_status != "401") {
169
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
170
+ Mage::throwException(Mage::helper('adminhtml')->__("Connection error, please try again later."));
171
+ } else {
172
+ if (!$response_obj["success"]) //error
173
+ {
174
+ Mage::getModel('core/config')->saveConfig('aftership_options/messages/status', 0);
175
+ Mage::throwException(Mage::helper('adminhtml')->__("Incorrect API Key"));
176
+ }
177
+ }
178
+ }
179
+ }
app/code/community/Aftership/Track/Model/Resource/Mysql4/Setup.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Resource_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
3
+ }
4
+ ?>
app/code/community/Aftership/Track/Model/Track.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Track extends Mage_Core_Model_Abstract
3
+ {
4
+ protected function _construct()
5
+ {
6
+ $this->_init('track/track');
7
+ }
8
+ }
9
+ ?>
app/code/community/Aftership/Track/Model/Words.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_Model_Words
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>0, 'label'=>Mage::helper('aftership')->__('Disable')),
8
+ array('value'=>1, 'label'=>Mage::helper('aftership')->__('Enable')),
9
+ );
10
+ }
11
+
12
+ }
13
+ ?>
app/code/community/Aftership/Track/controllers/IndexController.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ class Aftership_Track_IndexController extends Mage_Core_Controller_Front_Action {
3
+
4
+ public function indexAction() {
5
+ }
6
+ }
7
+ ?>
app/code/community/Aftership/Track/etc/config.xml ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <global>
4
+ <models>
5
+ <track>
6
+ <class>Aftership_Track_Model</class>
7
+ <resourceModel>track_mysql4</resourceModel>
8
+ </track>
9
+ <track_mysql4>
10
+ <class>Aftership_Track_Model_Mysql4</class>
11
+ <entities>
12
+ <track>
13
+ <table>as_track</table>
14
+ </track>
15
+ <!--<user>
16
+ <table>as_user</table>
17
+ </user>-->
18
+ </entities>
19
+ </track_mysql4>
20
+ <status>
21
+ <class>Aftership_Track_Model</class>
22
+ </status>
23
+ <notification>
24
+ <class>Aftership_Track_Model</class>
25
+ </notification>
26
+ </models>
27
+ <resources>
28
+ <track_write>
29
+ <connection>
30
+ <use>core_write</use>
31
+ </connection>
32
+ </track_write>
33
+ <track_read>
34
+ <connection>
35
+ <use>core_read</use>
36
+ </connection>
37
+ </track_read>
38
+ <track_setup>
39
+ <setup>
40
+ <module>Aftership_Track</module>
41
+ <class>Aftership_Track_Model_Resource_Mysql4_Setup</class>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </track_setup>
47
+ </resources>
48
+ <helpers>
49
+ <aftership>
50
+ <class>Aftership_Track_Helper</class>
51
+ </aftership>
52
+ </helpers>
53
+ </global>
54
+ <modules>
55
+ <Aftership_Track>
56
+ <version>0.1.0</version>
57
+ </Aftership_Track>
58
+ </modules>
59
+ <frontend>
60
+ <routers>
61
+ <track>
62
+ <use>standard</use>
63
+ <args>
64
+ <module>Aftership_Track</module>
65
+ <frontName>track</frontName>
66
+ </args>
67
+ </track>
68
+ </routers>
69
+ </frontend>
70
+ <adminhtml>
71
+ <events>
72
+ <sales_order_shipment_track_save_after>
73
+ <observers>
74
+ <fishpig_save_product_data>
75
+ <type>singleton</type>
76
+ <class>track/observer</class>
77
+ <method>salesOrderShipmentTrackSaveAfter</method>
78
+ </fishpig_save_product_data>
79
+ </observers>
80
+ </sales_order_shipment_track_save_after>
81
+ <admin_system_config_changed_section_aftership_options>
82
+ <observers>
83
+ <index>
84
+ <class>track/observer</class>
85
+ <method>adminSystemConfigChangedSectionAftership</method>
86
+ </index>
87
+ </observers>
88
+ </admin_system_config_changed_section_aftership_options>
89
+ </events>
90
+ <acl>
91
+ <resources>
92
+ <admin>
93
+ <children>
94
+ <system>
95
+ <children>
96
+ <config>
97
+ <children>
98
+ <aftership_options>
99
+ <title>Aftership tracking config</title>
100
+ </aftership_options>
101
+ </children>
102
+ </config>
103
+ </children>
104
+ </system>
105
+ </children>
106
+ </admin>
107
+ </resources>
108
+ </acl>
109
+ </adminhtml>
110
+ </config>
app/code/community/Aftership/Track/etc/system.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <aftershipconfig translate="label" module="aftership">
4
+ <label>Aftership</label>
5
+ <sort_order>99999</sort_order>
6
+ </aftershipconfig>
7
+ </tabs>
8
+ <sections>
9
+ <aftership_options translate="label" module="aftership">
10
+ <label>AfterShip Config Options</label>
11
+ <tab>aftershipconfig</tab>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <messages translate="label">
19
+ <label>Account setting</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <api_key>
27
+ <label>API key</label>
28
+ <frontend_type>text</frontend_type>
29
+ <sort_order>10</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>0</show_in_store>
33
+ <comment>You can find your API key in <![CDATA[<a target='_blank' href="https://www.aftership.com/connect/magento">https://www.aftership.com/connect/magento</a>]]></comment>
34
+ </api_key>
35
+ <status>
36
+ <label>Status</label>
37
+ <frontend_type>Select</frontend_type>
38
+ <source_model>status/words</source_model>
39
+ <sort_order>30</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </status>
44
+ <!--<notification>
45
+ <label>Notification</label>
46
+ <frontend_type>Multiselect</frontend_type>
47
+ <source_model>notification/methods</source_model>
48
+ <sort_order>40</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>0</show_in_store>
52
+ </notification>-->
53
+ </fields>
54
+ </messages>
55
+ </groups>
56
+ </aftership_options>
57
+ </sections>
58
+ </config>
app/code/community/Aftership/Track/sql/track_setup/{mysql4-install-0.1.0.php → mysql4-install-0.1.16.php} RENAMED
File without changes
package.xml CHANGED
@@ -1,23 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>aftership</name>
4
- <version>0.2.1</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. &#xD;
10
- 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>
11
- <description>Users can simply link their online stores to Aftership and view all packages in one place. Online&#xD;
12
- stores can also automatically inform their customers of the latest delivery status through SMS, email and&#xD;
13
- Twitter. All the messages are white-labeled and can be customized for any marketing opportunities. Aftership&#xD;
14
- also provides online stores a reporting tool so that they can easily find out any shipping problems like delayed&#xD;
15
- delivery and solve immediately. Aftership currently supports over 40 shipping companies worldwide.</description>
16
- <notes>Minor bugs fixed</notes>
17
  <authors><author><name>aftership</name><user>aftership</user><email>support@aftership.com</email></author></authors>
18
  <date>2012-10-20</date>
19
- <time>14:37:30</time>
20
- <contents><target name="magecommunity"><dir name="Aftership"><dir name="Track"><dir name="sql"><dir name="track_setup"><file name="mysql4-install-0.1.0.php" hash="a8f81083585c85a89e8a3097f5f3045c"/></dir></dir></dir></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.2.13</min><max>5.4.8</max></php></required></dependencies>
23
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>aftership</name>
4
+ <version>0.2.2</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.&#xD;
10
+ 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>
11
+ <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. 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>
12
+ <notes>Bug fixes</notes>
 
 
 
 
13
  <authors><author><name>aftership</name><user>aftership</user><email>support@aftership.com</email></author></authors>
14
  <date>2012-10-20</date>
15
+ <time>15:01:04</time>
16
+ <contents><target name="magecommunity"><dir name="Aftership"><dir name="Track"><dir name="Helper"><file name="Data.php" hash="970d03deb3e5fc478f5d86e5ff3670cb"/></dir><dir name="Model"><file name="Methods.php" hash="d9fa7ef3df0353c01662ff4bdf210f60"/><dir name="Mysql4"><dir name="Track"><file name="Collection.php" hash="336c4b0fba8db78e1222da01aa8c5744"/></dir><file name="Track.php" hash="90ad226fa98576fceb223b85fe88b642"/></dir><file name="Observer.php" hash="9fea70bb15867c43dfb59a1e62a45829"/><dir name="Resource"><dir name="Mysql4"><file name="Setup.php" hash="b53f65ecc832752c8394f0da74b2f90d"/></dir></dir><file name="Track.php" hash="eb12833d5f084b0b919cbde45f8170eb"/><file name="Words.php" hash="7789e47b991f718fb3097b5e274eb71f"/></dir><dir name="controllers"><file name="IndexController.php" hash="3ee34f42957e816ff336f8f8215a218b"/></dir><dir name="etc"><file name="config.xml" hash="44b407dcd58774176a2a37191daf04a2"/><file name="system.xml" hash="857fa4fae0433c10ba468bff794ca9ef"/></dir><dir name="sql"><dir name="track_setup"><file name="mysql4-install-0.1.16.php" hash="a8f81083585c85a89e8a3097f5f3045c"/></dir></dir><file name=".DS_Store" hash="822777d708619165d544d3256174adc2"/></dir><file name=".DS_Store" hash="187c68966589e21d1b51b9a56354abe6"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.13</min><max>5.4.8</max></php></required></dependencies>
19
  </package>