ship200_onebyone - Version 1.0.3

Version Notes

changed postback logic code

Download this release

Release Info

Developer Ship200
Extension ship200_onebyone
Version 1.0.3
Comparing to
See all releases


Code changes from version 1.0.2 to 1.0.3

app/code/local/Ship200/Onebyone/controllers/IndexController.php CHANGED
@@ -1,92 +1,125 @@
1
  <?php
2
-
3
-
4
-
5
  class Ship200_Onebyone_IndexController extends Mage_Core_Controller_Front_Action
6
-
7
  {
8
-
9
-
10
-
11
- public function postbackAction(){
12
-
13
-
14
-
15
- $secret_key = Mage::getStoreConfig('onebyone/info/appkey');
16
- $order_status_tracking = Mage::getStoreConfig('onebyone/info/order_status_tracking');
17
- // $notify_customer_setting = Mage::getStoreConfig('onebyone/info/notify_customer');
18
- $notify_customer_setting = 1;
19
-
20
-
21
-
22
- if($notify_customer_setting == "1"){
23
- $notifycustomer="true";
24
- }else{
25
- $notifycustomer="false";
26
- }
27
-
28
- if($secret_key == ""){ echo "The Secret Key was never setup. Please refer to read_me file"; exit;}
29
-
30
- if($order_status_tracking == ""){ echo "Please Select The Order Status From Admin For Update With Tracking"; exit;}
31
-
32
- #Extra security
33
- // Check that request is coming from Ship200 Server
34
- $allowed_servers = file_get_contents('http://www.ship200.com/instructions/allowed_servers.txt');
35
- $servers_array = explode(",",$allowed_servers);
36
-
37
- $server = 0;
38
- foreach($servers_array as $ip){
39
- if($_SERVER['REMOTE_ADDR'] == $ip){$server = 1;}
40
- }
41
- if($server == 0){ echo "Incorrect Server"; exit;}
42
- // Check that request is coming from Ship200 Server
43
-
44
-
45
- if($_POST['update_tracking'] != "" && $_GET['id'] == $secret_key){
46
-
47
-
48
- $order=Mage::getModel("sales/order")->loadByIncrementId($_POST['keyForUpdate']);
49
-
50
- if($order->canShip()){
51
-
52
- $arrTracking = array(
53
- 'carrier_code' => strtolower($_POST['carrier']),
54
- 'title' => $_POST[service]." - (Ship200 OneByOne)",
55
- 'number' => $_POST['tracking'],
56
- );
57
-
58
- $itemQty = $order->getItemsCollection()->count();
59
- $shipment = $order->prepareShipment();
60
- if($shipment){
61
- $track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
62
- $shipment->addTrack($track);
63
- $shipment->register();
64
- $transactionSave = Mage::getModel('core/resource_transaction')
65
- ->addObject($shipment)
66
- ->addObject($shipment->getOrder())
67
- ->save();
68
- }
69
-
70
- }
71
-
72
- $order->setData('state', $order_status_tracking);
73
- $order->setStatus($order_status_tracking);
74
- $comment = addslashes($_POST['carrier'])." tracking#: ".addslashes($_POST['tracking']);
75
- $history = $order->addStatusHistoryComment($comment, false);
76
- $history->setIsCustomerNotified($notifycustomer);
77
- $order->save();
78
-
79
- echo "Tracking Number: Inserted";
80
-
81
- }else{
82
- echo "Failed to Update Tracking";
83
- }
84
- }
85
-
86
-
87
-
88
- }
89
-
90
-
91
-
92
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
 
 
 
2
  class Ship200_Onebyone_IndexController extends Mage_Core_Controller_Front_Action
 
3
  {
4
+ public function postbackAction(){
5
+
6
+ $secret_key = Mage::getStoreConfig('onebyone/info/appkey');
7
+ $order_status_tracking = Mage::getStoreConfig('onebyone/info/order_status_tracking');
8
+ $notify_customer_setting = 1;
9
+
10
+ if($secret_key == ""){ echo "The Secret Key was never setup. Please refer to read_me file"; exit;}
11
+
12
+ if($order_status_tracking == ""){ echo "Please Select The Order Status From Admin For Update With Tracking"; exit;}
13
+
14
+ #Extra security
15
+ // Check that request is coming from Ship200 Server
16
+ $allowed_servers = file_get_contents('http://www.ship200.com/instructions/allowed_servers.txt');
17
+ if (!$allowed_servers) $allowed_servers = '173.192.194.99,173.192.194.98,108.58.55.190,45.33.71.107,45.33.73.63,45.33.89.56,45.33.85.63,97.107.136.135,45.79.162.158,45.79.136.18,45.79.130.178';
18
+ $servers_array = explode(",",$allowed_servers);
19
+
20
+ $server = 0;
21
+ foreach($servers_array as $ip)
22
+ if($_SERVER['REMOTE_ADDR'] == $ip)
23
+ $server = 1;
24
+
25
+ if($server == 0){ echo "Incorrect Server"; exit;}
26
+ // Check that request is coming from Ship200 Server
27
+
28
+ #DEBUG
29
+ /* $_POST['update_tracking'] = 100000200 ;
30
+ $_POST['keyForUpdate'] = 100000200 ;
31
+ $_POST['carrier'] = 'USPS';
32
+ $_POST['service'] = 'Priority Mail';
33
+ $_POST['tracking'] = '123456789';*/
34
+
35
+ $update_tracking = $this->getRequest()->getParam('update_tracking');
36
+ $id = $this->getRequest()->getParam('id');
37
+ if(isset($update_tracking) && isset($id) && $id == $secret_key){
38
+
39
+ $order = Mage::getModel("sales/order")->loadByIncrementId($this->getRequest()->getParam('keyForUpdate'));
40
+
41
+ $customerEmailComments = 'Your Order Has Been Shipped';
42
+
43
+ if (!$order->getId()) {
44
+ echo "Order does not exist, for the Shipment process to complete";
45
+ exit();
46
+ }
47
+
48
+ if ($order->canShip()) {
49
+ try {
50
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($this->_getItemQtys($order));
51
+
52
+ $shipmentCarrierCode = strtolower($this->getRequest()->getParam('carrier'));
53
+ $shipmentCarrierTitle = $this->getRequest()->getParam('service')." - (Ship200 OneByOne)";
54
+
55
+ $arrTracking = array(
56
+ 'carrier_code' => isset($shipmentCarrierCode) ? $shipmentCarrierCode : $order->getShippingCarrier()->getCarrierCode(),
57
+ 'title' => isset($shipmentCarrierTitle) ? $shipmentCarrierTitle : $order->getShippingCarrier()->getConfigData('title'),
58
+ 'number' => $this->getRequest()->getParam('tracking'),
59
+ );
60
+
61
+ $track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
62
+ $shipment->addTrack($track);
63
+
64
+ $shipment->register();
65
+
66
+ $this->_saveShipment($shipment, $order, $customerEmailComments);
67
+
68
+ $this->_saveOrder($order, $order_status_tracking);
69
+
70
+ echo "Tracking Number: Inserted";
71
+ } catch (Exception $e) {
72
+ var_dump($e);
73
+ exit();
74
+ }
75
+ }else{
76
+ echo "Failed to Update Tracking, Order maybe already shipped";
77
+ }
78
+ }else
79
+ echo "Failed to Update Tracking";
80
+
81
+ exit();
82
+ }
83
+
84
+ protected function _getItemQtys(Mage_Sales_Model_Order $order)
85
+ {
86
+ $qty = array();
87
+
88
+ foreach ($order->getAllItems() as $_eachItem) {
89
+ if ($_eachItem->getParentItemId()) {
90
+ $qty[$_eachItem->getParentItemId()] = $_eachItem->getQtyOrdered();
91
+ } else {
92
+ $qty[$_eachItem->getId()] = $_eachItem->getQtyOrdered();
93
+ }
94
+ }
95
+
96
+ return $qty;
97
+ }
98
+
99
+ protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
100
+ {
101
+ $shipment->getOrder()->setIsInProcess(true);
102
+ $transactionSave = Mage::getModel('core/resource_transaction')
103
+ ->addObject($shipment)
104
+ ->addObject($order)
105
+ ->save();
106
+
107
+ /*$emailSentStatus = $shipment->getData('email_sent');
108
+ if (!$emailSentStatus) {
109
+ $shipment->sendEmail(true, $customerEmailComments);
110
+ $shipment->setEmailSent(true);
111
+ }*/
112
+
113
+ return $this;
114
+ }
115
+
116
+ protected function _saveOrder(Mage_Sales_Model_Order $order, $status)
117
+ {
118
+ $order->setData('state', $status);
119
+ $order->setData('status', $status);
120
+
121
+ $order->save();
122
+
123
+ return $this;
124
+ }
125
+ }
app/code/local/Ship200/Onebyone/etc/system.xml CHANGED
@@ -109,7 +109,7 @@
109
  <show_in_store>1</show_in_store>
110
 
111
  <comment>
112
- <![CDATA[1. Login in into your Ship200.com account. </br> 2. On top menu go to "Bulk Processing" -> "Generate Key" </br>3. Click "Generate Key", then replace "XXXXXXXXXX-XXX" with your generated key in the next step]]>
113
  </comment>
114
 
115
 
109
  <show_in_store>1</show_in_store>
110
 
111
  <comment>
112
+ <![CDATA[<br>1. Login in into your Ship200.com account. <br> 2. On top menu go to "Settings" -&gt; "OneByOne Plugin" <br> 3. Click "Generate Key for OneByOne Plugin", then insert your key into "Ship200 Key" field on this page.]]>
113
  </comment>
114
 
115
 
app/design/adminhtml/default/default/template/onebyone/sales/order/view/info.phtml CHANGED
@@ -161,9 +161,9 @@ $shipping_address = $_order->getShippingAddress();
161
 
162
  '<?php echo addslashes($_order->getGrandTotal()) ?>', //10 Declared Value
163
 
164
- '', //11 Weight
165
 
166
- '', //12 Weight Units (lb or oz): valid values are 'lb' or 'oz'
167
 
168
  '', //13 Dimensions Length
169
 
161
 
162
  '<?php echo addslashes($_order->getGrandTotal()) ?>', //10 Declared Value
163
 
164
+ '<?php echo addslashes(round($_order->getWeight(), 2)) ?>', //11 Weight
165
 
166
+ 'lb', //12 Weight Units (lb or oz): valid values are 'lb' or 'oz'
167
 
168
  '', //13 Dimensions Length
169
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ship200_onebyone</name>
4
- <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
@@ -10,11 +10,11 @@
10
  <description>Ship200 is Multi Carrier (Fedex, UPS, USPS) Shipping Software which allows you to print shipping labels in bulk or individually and integrate process of creating labels directly into you Magento. &#xD;
11
  &#xD;
12
  This Plugin adds "Create Shipping Label" and "Make Return Label" to order detail page. </description>
13
- <notes>Initial Release</notes>
14
- <authors><author><name>Ship200</name><user>Alex</user><email>support@ship200.com</email></author></authors>
15
- <date>2015-03-23</date>
16
- <time>19:32:37</time>
17
- <contents><target name="magelocal"><dir name="Ship200"><dir name="Onebyone"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="9e493ba3a3351061af3c655d9b09bab2"/></dir></dir><file name="Ship200.php" hash="c43d15e9f75a7fdfc163c8314e9646a6"/><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="1f325984c1daa1704e1e8529f6af8fd5"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="684696810527e63cab3f4dd0b0e0f042"/></dir><dir name="Model"><dir name="Source"><file name="Carrier.php" hash="cee4a17e17bdfa176ebcf090b0645e51"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="Ship200Controller.php" hash="c0570021dacf790f74514a55a82fc960"/></dir><file name="IndexController.php" hash="12846fd718f8e61f41b94041c454f55c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f3ca9a4f15afc39ce63aa4478c88bfcf"/><file name="config.xml" hash="bad61bb65a75e699364ded5258df0ddd"/><file name="system.xml" hash="b09f4850717c6ba6337459ac9b238c4f"/></dir><dir name="sql"><dir name="onebyone_setup"><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="46662fec5ded7452fb9c206d17a724b5"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="Ship200_onebyone.xml" hash="958bafb8d90b63cf2d8c783a0eadc7d5"/></dir><dir name="template"><dir name="onebyone"><dir name="sales"><dir name="order"><dir name="view"><file name="info.phtml" hash="f50ef6fde79f7288ca7e645bb22c6fe6"/><dir name="tab"><file name="info.phtml" hash="f8aea0bff59cbf606a6846c11f2e8556"/></dir></dir></dir></dir><file name="ship200.phtml" hash="0a12ec3e50b74ebe1fbacfc452a698df"/><dir name="system"><dir name="config"><file name="button.phtml" hash="de35b412e052ce2c082212dde277e79c"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ship200_Onebyone.xml" hash="c66ea49dc8acfcc0ed30a3348c7c29f7"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ship200_onebyone</name>
4
+ <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
10
  <description>Ship200 is Multi Carrier (Fedex, UPS, USPS) Shipping Software which allows you to print shipping labels in bulk or individually and integrate process of creating labels directly into you Magento. &#xD;
11
  &#xD;
12
  This Plugin adds "Create Shipping Label" and "Make Return Label" to order detail page. </description>
13
+ <notes>changed postback logic code</notes>
14
+ <authors><author><name>Ship200</name><user>Ship200</user><email>support@ship200.com</email></author></authors>
15
+ <date>2015-11-12</date>
16
+ <time>18:57:49</time>
17
+ <contents><target name="magelocal"><dir name="Ship200"><dir name="Onebyone"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="9e493ba3a3351061af3c655d9b09bab2"/></dir></dir><file name="Ship200.php" hash="c43d15e9f75a7fdfc163c8314e9646a6"/><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="1f325984c1daa1704e1e8529f6af8fd5"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="684696810527e63cab3f4dd0b0e0f042"/></dir><dir name="Model"><dir name="Source"><file name="Carrier.php" hash="cee4a17e17bdfa176ebcf090b0645e51"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="Ship200Controller.php" hash="c0570021dacf790f74514a55a82fc960"/></dir><file name="IndexController.php" hash="5c4e597c8019d5b2b16df937624669ab"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f3ca9a4f15afc39ce63aa4478c88bfcf"/><file name="config.xml" hash="bad61bb65a75e699364ded5258df0ddd"/><file name="system.xml" hash="a996554ab4483405fcf2ca613701ced0"/></dir><dir name="sql"><dir name="onebyone_setup"><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="46662fec5ded7452fb9c206d17a724b5"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="Ship200_onebyone.xml" hash="958bafb8d90b63cf2d8c783a0eadc7d5"/></dir><dir name="template"><dir name="onebyone"><dir name="sales"><dir name="order"><dir name="view"><file name="info.phtml" hash="177e04de197417932a032566f4589700"/><dir name="tab"><file name="info.phtml" hash="f8aea0bff59cbf606a6846c11f2e8556"/></dir></dir></dir></dir><file name="ship200.phtml" hash="0a12ec3e50b74ebe1fbacfc452a698df"/><dir name="system"><dir name="config"><file name="button.phtml" hash="de35b412e052ce2c082212dde277e79c"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ship200_Onebyone.xml" hash="c66ea49dc8acfcc0ed30a3348c7c29f7"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
20
  </package>