Shopgo_SkynetShipping - Version 1.0.7

Version Notes

The first release of SkyNet Worldwide Express module.

Download this release

Release Info

Developer Moe Ghashim
Extension Shopgo_SkynetShipping
Version 1.0.7
Comparing to
See all releases


Version 1.0.7

Files changed (24) hide show
  1. app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/Sales/Order/Shipment/Create/Form/Abstract.php +33 -0
  2. app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/Sales/Order/Shipment/Create/Form/Shipment.php +51 -0
  3. app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/System/Config/Form/ServiceListButton.php +33 -0
  4. app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/System/Config/Form/VerifyAccountButton.php +33 -0
  5. app/code/community/Shopgo/SkynetShipping/Helper/Data.php +293 -0
  6. app/code/community/Shopgo/SkynetShipping/Model/Carrier/Skynet.php +136 -0
  7. app/code/community/Shopgo/SkynetShipping/Model/Resource/Service.php +20 -0
  8. app/code/community/Shopgo/SkynetShipping/Model/Resource/Service/Collection.php +10 -0
  9. app/code/community/Shopgo/SkynetShipping/Model/Service.php +85 -0
  10. app/code/community/Shopgo/SkynetShipping/Model/Shipment.php +512 -0
  11. app/code/community/Shopgo/SkynetShipping/Model/Shipment/Source/Typeofshipment.php +29 -0
  12. app/code/community/Shopgo/SkynetShipping/Model/System/Config/Source/Service.php +34 -0
  13. app/code/community/Shopgo/SkynetShipping/controllers/Adminhtml/SkynetController.php +100 -0
  14. app/code/community/Shopgo/SkynetShipping/etc/config.xml +85 -0
  15. app/code/community/Shopgo/SkynetShipping/etc/system.xml +227 -0
  16. app/code/community/Shopgo/SkynetShipping/sql/skynetshipping_setup/mysql4-install-1.0.0.php +25 -0
  17. app/design/adminhtml/default/default/layout/shopgo/skynet_shipping.xml +34 -0
  18. app/design/adminhtml/default/default/template/shopgo/skynet_shipping/sales/order/shipment/create/form/shipment.phtml +48 -0
  19. app/design/adminhtml/default/default/template/shopgo/skynet_shipping/system/config/service_list_button.phtml +61 -0
  20. app/design/adminhtml/default/default/template/shopgo/skynet_shipping/system/config/verify_account_button.phtml +47 -0
  21. app/etc/modules/Shopgo_SkynetShipping.xml +12 -0
  22. package.xml +21 -0
  23. skin/adminhtml/default/default/shopgo/skynet_shipping/sales/order/shipment/create/form/css/main.css +7 -0
  24. skin/adminhtml/default/default/shopgo/skynet_shipping/sales/order/shipment/create/form/css/shipment.css +11 -0
app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/Sales/Order/Shipment/Create/Form/Abstract.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Shopgo_SkynetShipping_Block_Adminhtml_Sales_Order_Shipment_Create_Form_Abstract extends Mage_Adminhtml_Block_Sales_Order_Abstract
4
+ {
5
+ abstract protected function isEnabled();
6
+
7
+ abstract protected function getFormFieldData($field, $data = '');
8
+
9
+ /**
10
+ * Retrieve invoice order
11
+ *
12
+ * @return Mage_Sales_Model_Order
13
+ */
14
+ public function getOrder()
15
+ {
16
+ return $this->getShipment()->getOrder();
17
+ }
18
+
19
+ /**
20
+ * Retrieve shipment model instance
21
+ *
22
+ * @return Mage_Sales_Model_Order_Shipment
23
+ */
24
+ public function getShipment()
25
+ {
26
+ return Mage::registry('current_shipment');
27
+ }
28
+
29
+ public function getCountryCodeOptions()
30
+ {
31
+ return Mage::getModel('adminhtml/system_config_source_country')->toOptionArray();
32
+ }
33
+ }
app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/Sales/Order/Shipment/Create/Form/Shipment.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Block_Adminhtml_Sales_Order_Shipment_Create_Form_Shipment extends Shopgo_SkynetShipping_Block_Adminhtml_Sales_Order_Shipment_Create_Form_Abstract
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ $shipmentData = Mage::getSingleton('adminhtml/session')->getShipSkynetShipmentData();
10
+
11
+ if ($shipmentData) {
12
+ $this->setFormData($shipmentData);
13
+
14
+ Mage::getSingleton('adminhtml/session')->unsShipSkynetShipmentData();
15
+
16
+ if (Mage::registry('setShipSkynetFormDefaultData')) {
17
+ Mage::unregister('setShipSkynetFormDefaultData');
18
+ }
19
+ } else {
20
+ if (!Mage::registry('setShipSkynetFormDefaultData')) {
21
+ Mage::register('setShipSkynetFormDefaultData', 1);
22
+ }
23
+ }
24
+ }
25
+
26
+ protected function isEnabled()
27
+ {
28
+ return Mage::getModel('skynetshipping/shipment')->isEnabled();
29
+ }
30
+
31
+ public function getShipmentTypeOptions()
32
+ {
33
+ $options = Mage::getModel('skynetshipping/shipment_source_typeofshipment')
34
+ ->toOptionArray();
35
+
36
+ return $options;
37
+ }
38
+
39
+ protected function getFormFieldData($field, $data = '')
40
+ {
41
+ if (Mage::registry('setShipSkynetFormDefaultData')) {
42
+ switch ($field) {
43
+ case 'consignor_ref':
44
+ $data = $this->getOrder()->getIncrementId();
45
+ break;
46
+ }
47
+ }
48
+
49
+ return $data;
50
+ }
51
+ }
app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/System/Config/Form/ServiceListButton.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Block_Adminhtml_System_Config_Form_ServiceListButton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $template = $this->setTemplate('shopgo/skynet_shipping/system/config/service_list_button.phtml');
9
+ }
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ return $this->_toHtml();
14
+ }
15
+
16
+ public function getAjaxActionUrl()
17
+ {
18
+ return Mage::helper('adminhtml')->getUrl('adminhtml/skynet/getservicelist');
19
+ }
20
+
21
+ public function getButtonHtml()
22
+ {
23
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(
24
+ array(
25
+ 'id' => 'skynet_service_list_trigger',
26
+ 'label' => $this->helper('adminhtml')->__('Retrieve Service List'),
27
+ 'onclick' => 'javascript:shopgo.skynetShipping.serviceListButton.getList(); return false;'
28
+ )
29
+ );
30
+
31
+ return $button->toHtml();
32
+ }
33
+ }
app/code/community/Shopgo/SkynetShipping/Block/Adminhtml/System/Config/Form/VerifyAccountButton.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Block_Adminhtml_System_Config_Form_VerifyAccountButton extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $template = $this->setTemplate('shopgo/skynet_shipping/system/config/verify_account_button.phtml');
9
+ }
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ return $this->_toHtml();
14
+ }
15
+
16
+ public function getAjaxVerifyAccountUrl()
17
+ {
18
+ return Mage::helper('adminhtml')->getUrl('adminhtml/skynet/verifyaccount');
19
+ }
20
+
21
+ public function getButtonHtml()
22
+ {
23
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(
24
+ array(
25
+ 'id' => 'skynet_account_checker',
26
+ 'label' => $this->helper('adminhtml')->__('Verify Account'),
27
+ 'onclick' => 'javascript:shopgo.skynetShipping.verifyAccountButton.verifyAccount(); return false;'
28
+ )
29
+ );
30
+
31
+ return $button->toHtml();
32
+ }
33
+ }
app/code/community/Shopgo/SkynetShipping/Helper/Data.php ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Helper_Data extends Shopgo_ShippingCore_Helper_Abstract
4
+ {
5
+ const GENERAL_CONTACT_EMAIL = 'trans_email/ident_general/email';
6
+
7
+ const CARRIERS_SKYNET_SYSTEM_PATH = 'carriers/skynet/';
8
+ const SHIPPING_ORIGIN_SYSTEM_PATH = 'shipping/origin/';
9
+ const SKYNET_SETTINGS_SYSTEM_PATH = 'shipping/skynet_settings/';
10
+
11
+ const RATE_RESPONSE_CURRENCY_XPATH = 'TARIF/RATECURRENCY';
12
+ const RATE_RESPONSE_FINAL_CHARGES_XPATH = 'TARIF/FINALCHARGES';
13
+ const RATE_RESPONSE_VOL_WEIGHT_XPATH = 'TARIF/VOLWEIGHTOFSHIPMENT';
14
+ const RATE_RESPONSE_CHARGED_WEIGHT_XPATH = 'TARIF/CHARGEDWEIGHT';
15
+
16
+ const SHIPMENT_RESPONSE_NUMBER_XPATH = 'ShipmentNumber';
17
+ //const PICKUP_RESPONSE_REF_NUMBER_XPATH = 'PickupReferenceNumber';
18
+ //const TRACKING_RESPONSE_HISTORY_XPATH = 'TODO';
19
+ //const LABEL_RESPONSE_PDF_XPATH = 'TODO';
20
+ const SERVICE_LIST_RESPONSE_XPATH = 'ServiceList';
21
+
22
+
23
+ protected $_logFile = 'skynet_shipping.log';
24
+
25
+
26
+ public function getOriginSupplier($section = '')
27
+ {
28
+ $data = array();
29
+
30
+ $originInfo = array(
31
+ 'consignor_name' => ucwords(strtolower(trim($this->getConfigData('consignor_name', 'skynet_settings')))),
32
+ 'country_code' => strtoupper(trim($this->getConfigData('country_id', 'shipping_origin'))),
33
+ 'state_or_province_code' => trim($this->getConfigData('region_id', 'shipping_origin')),
34
+ 'zipcode' => trim($this->getConfigData('postcode', 'shipping_origin')),
35
+ 'city' => trim($this->getConfigData('city', 'shipping_origin')),
36
+ 'address_line1' => trim($this->getConfigData('street_line1', 'shipping_origin')),
37
+ 'address_line2' => trim($this->getConfigData('street_line2', 'shipping_origin')),
38
+ 'phone_number' => trim($this->getConfigData('phone_number', 'additional_info')),
39
+ 'fax_number' => trim($this->getConfigData('fax_number', 'additional_info')),
40
+ 'cellphone' => trim($this->getConfigData('cellphone', 'additional_info')),
41
+ 'email' => trim($this->getConfigData('email', 'additional_info'))
42
+ );
43
+
44
+ $skynetAccount = array(
45
+ 'username' => trim(Mage::helper('core')->decrypt($this->getConfigData('username', 'carriers_skynet'))),
46
+ 'password' => trim(Mage::helper('core')->decrypt($this->getConfigData('password', 'carriers_skynet'))),
47
+ 'station_code' => strtoupper(trim($this->getConfigData('station_code', 'carriers_skynet'))),
48
+ 'consignor_account' => trim($this->getConfigData('consignor_account', 'carriers_skynet'))
49
+ );
50
+
51
+ switch ($section) {
52
+ case 'origin_info':
53
+ $data = $originInfo;
54
+ break;
55
+ case 'skynet_account':
56
+ $data = $skynetAccount;
57
+ break;
58
+ default:
59
+ $data = array_merge($skynetAccount, $originInfo);
60
+ }
61
+
62
+ return $data;
63
+ }
64
+
65
+ public function getClientInfo($source)
66
+ {
67
+ if (!$source) {
68
+ $source = $this->getOriginSupplier('skynet_account');
69
+ }
70
+
71
+ $clientInfo = array(
72
+ 'UserName' => trim($source['username']),
73
+ 'Password' => trim($source['password']),
74
+ 'StationCode' => strtoupper(trim($source['station_code'])),
75
+ 'ConsignorAccount' => trim($source['consignor_account'])
76
+ );
77
+
78
+ return $clientInfo;
79
+ }
80
+
81
+ public function getConfigData($var, $type, $store = null)
82
+ {
83
+ $path = '';
84
+
85
+ switch ($type) {
86
+ case 'carriers_skynet':
87
+ $path = self::CARRIERS_SKYNET_SYSTEM_PATH;
88
+ break;
89
+ case 'shipping_origin':
90
+ $path = self::SHIPPING_ORIGIN_SYSTEM_PATH;
91
+ break;
92
+ case 'skynet_settings':
93
+ $path = self::SKYNET_SETTINGS_SYSTEM_PATH;
94
+ break;
95
+ }
96
+
97
+ return Mage::getStoreConfig($path . $var, $store);
98
+ }
99
+
100
+ public function soapClient($method, $callParams, $scOptions = array())
101
+ {
102
+ $wsdl = $this->_getWsdl($method);
103
+ $result = null;
104
+
105
+ if (!isset($scOptions['soap_version'])) {
106
+ $scOptions['soap_version'] = SOAP_1_2;
107
+ }
108
+
109
+ if (!isset($scOptions['trace'])) {
110
+ $scOptions['trace'] = 1;
111
+ }
112
+
113
+ if (!isset($scOptions['exceptions'])) {
114
+ $scOptions['exceptions'] = 0;
115
+ }
116
+
117
+ try {
118
+ $soapClient = new SoapClient($wsdl, $scOptions);
119
+
120
+ if ($actionHeader = $this->_getSoapHeader($method)) {
121
+ $soapClient->__setSoapHeaders($actionHeader);
122
+ }
123
+
124
+ $result = $this->_soapClientCall($method, $soapClient, $callParams);
125
+
126
+ if ($result instanceof SoapFault) {
127
+ $this->log($result->faultstring);
128
+ $result = '[soapfault]';
129
+ }
130
+ } catch (SoapFault $sf) {
131
+ $this->log($sf->faultstring);
132
+ $result = '[soapfault]';
133
+ }
134
+
135
+ return $result;
136
+ }
137
+
138
+ private function _getSoapHeader($method)
139
+ {
140
+ $action = '';
141
+ $header = null;
142
+
143
+ switch ($method) {
144
+ case 'rate_request':
145
+ $action = 'http://tempuri.org/IService1/RequestRatesByObject';
146
+ break;
147
+ case 'create_shipment':
148
+ $action = 'http://tempuri.org/IService1/CreateShipmentByObject';
149
+ break;
150
+ case 'pickup_request':
151
+ $action = 'http://tempuri.org/IService1/PickupRequestByObject';
152
+ break;
153
+ case 'get_tracking':
154
+ $action = 'http://tempuri.org/GetSkyBillTrack';
155
+ break;
156
+ case 'get_label_pdf':
157
+ $action = 'http://tempuri.org/IService1/GetLabelPDF';
158
+ break;
159
+ case 'verify_account':
160
+ $action = 'http://tempuri.org/IService1/VerifyUserAccount';
161
+ break;
162
+ case 'get_service_list':
163
+ $action = 'http://tempuri.org/IService1/GetServiceList';
164
+ break;
165
+ default:
166
+ return $header;
167
+ }
168
+
169
+ $header = new SoapHeader(
170
+ 'http://www.w3.org/2005/08/addressing',
171
+ 'Action',
172
+ $action,
173
+ true
174
+ );
175
+
176
+ return $header;
177
+ }
178
+
179
+ private function _soapClientCall($method, $soapClient, $callParams)
180
+ {
181
+ $result = null;
182
+
183
+ switch ($method) {
184
+ case 'rate_request':
185
+ $result = $soapClient->RequestRatesByObject($callParams)->RequestRatesByObjectResult;
186
+ break;
187
+ case 'create_shipment':
188
+ $result = $soapClient->CreateShipmentByObject($callParams)->CreateShipmentByObjectResult;
189
+ break;
190
+ case 'pickup_request':
191
+ $result = $soapClient->PickupRequestByObject($callParams)->PickupRequestByObjectResult;
192
+ break;
193
+ case 'get_tracking':
194
+ $result = $soapClient->GetSkyBillTrack($callParams)->GetSkyBillTrackResult;
195
+ break;
196
+ case 'get_label_pdf':
197
+ $result = $soapClient->GetLabelPDF($callParams)->GetLabelPDFResult;
198
+ break;
199
+ case 'verify_account':
200
+ $result = $soapClient->VerifyUserAccount($callParams)->VerifyUserAccountResult;
201
+ break;
202
+ case 'get_service_list':
203
+ $result = $soapClient->GetServiceList($callParams)->GetServiceListResult;
204
+ break;
205
+ }
206
+
207
+ return $result;
208
+ }
209
+
210
+ private function _getWsdl($name)
211
+ {
212
+ $wsdl = 'http://api.skynetwwe.info/Service1.svc?wsdl';
213
+
214
+ switch ($name) {
215
+ case 'get_tracking':
216
+ $wsdl = 'https://iskynettrack.skynetwwe.info/TrackingService/TrackingService_v1.asmx?wsdl';
217
+ break;
218
+ }
219
+
220
+ return $wsdl;
221
+ }
222
+
223
+ public function debug($params, $file = '')
224
+ {
225
+ if ($this->getConfigData('debug', 'carriers_skynet')) {
226
+ $this->log($params, '', $file);
227
+ }
228
+ }
229
+
230
+ public function hideLogPrivacies($data)
231
+ {
232
+ $mask = '******';
233
+
234
+ $data['UserName'] = $mask;
235
+ $data['Password'] = $mask;
236
+
237
+ return $data;
238
+ }
239
+
240
+ public function parseXmlResponse($xml, $method)
241
+ {
242
+ $result = array();
243
+
244
+ $xmlObj = new Varien_Simplexml_Config($xml);
245
+
246
+ if (empty($xmlObj)) {
247
+ return $result;
248
+ }
249
+
250
+ $result['status'] = $xmlObj->getNode('StatusCode')->asArray();
251
+ $result['status_description'] = $xmlObj->getNode('StatusDescription')->asArray();
252
+ $result['request_id'] = $xmlObj->getNode('RequestID')->asArray();
253
+
254
+ if (false === strpos($result['status'], 'ERR')) {
255
+ switch ($method) {
256
+ case 'rate_request':
257
+ $result['currency'] = $xmlObj->getNode(self::RATE_RESPONSE_CURRENCY_XPATH)->asArray();
258
+ $result['price'] = $xmlObj->getNode(self::RATE_RESPONSE_FINAL_CHARGES_XPATH)->asArray();
259
+ $result['vol_weight'] = $xmlObj->getNode(self::RATE_RESPONSE_VOL_WEIGHT_XPATH)->asArray();
260
+ $result['charged_weight'] = $xmlObj->getNode(self::RATE_RESPONSE_CHARGED_WEIGHT_XPATH)->asArray();
261
+ break;
262
+ case 'shipping_service':
263
+ $result['shipment_number'] = $xmlObj->getNode(self::SHIPMENT_RESPONSE_NUMBER_XPATH)->asArray();
264
+ break;
265
+ //case 'pickup_request':
266
+ //$result['ref_number'] = $xmlObj->getNode(self::PICKUP_RESPONSE_REF_NUMBER_XPATH)->asArray();
267
+ //break;
268
+ //case 'get_tracking':
269
+ //$result['history'] = $xmlObj->getNode(self::TRACKING_RESPONSE_HISTORY_XPATH)->asArray();
270
+ //break;
271
+ //case 'get_label_pdf':
272
+ //$result['label'] = $xmlObj->getNode(self::LABEL_RESPONSE_PDF_XPATH)->asArray();
273
+ //break;
274
+ case 'verify_account':
275
+ $result['verify_account'] = $xmlObj->getNode()->asArray();
276
+ break;
277
+ case 'get_service_list':
278
+ $result['service_list'] = (array) $xmlObj->getNode(self::SERVICE_LIST_RESPONSE_XPATH);
279
+ $result['service_list'] = $result['service_list']['string'];
280
+ break;
281
+ }
282
+ }
283
+
284
+ return $result;
285
+ }
286
+
287
+ public function _getAdminhtmlShipmentForms($block)
288
+ {
289
+ $html = $block->getChildHtml('skynet_shipment');
290
+
291
+ return $html;
292
+ }
293
+ }
app/code/community/Shopgo/SkynetShipping/Model/Carrier/Skynet.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Carrier_Skynet extends Mage_Shipping_Model_Carrier_Abstract
4
+ implements Mage_Shipping_Model_Carrier_Interface
5
+ {
6
+ protected $_code = 'skynet';
7
+ protected $_result = null;
8
+
9
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
10
+ {
11
+ if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
12
+ return false;
13
+ }
14
+
15
+ $helper = Mage::helper('skynetshipping');
16
+
17
+ $this->_updateFreeMethodQuote($request);
18
+
19
+ if ($request->getFreeShipping()
20
+ || ($this->getConfigData('free_shipping_enable')
21
+ && $request->getBaseSubtotalInclTax() >=
22
+ $this->getConfigData('free_shipping_subtotal'))
23
+ ) {
24
+ return false;
25
+ }
26
+
27
+ $price = 0;
28
+ $error = false;
29
+ $methodTitle = '';
30
+
31
+ $sessionQoute = Mage::app()->getStore()->isAdmin()
32
+ ? Mage::getSingleton('adminhtml/session_quote')
33
+ : Mage::getSingleton('checkout/session');
34
+
35
+ $quote = $sessionQoute->getQuote();
36
+
37
+ $result = Mage::getModel('skynetshipping/shipment')
38
+ ->calculateRate($quote);
39
+
40
+ $error = false !== strpos($result['status'], 'ERR');
41
+ $errorMessage = $this->getConfigData('specificerrmsg');
42
+
43
+ if ($error
44
+ && $helper->getConfigData('skynet_error', 'carriers_skynet')) {
45
+ $errorMessage =
46
+ $skynetErrorMessage = 'SkyNet Error: ' . $result['status_description'];
47
+ }
48
+
49
+ $price = $result['price'];
50
+
51
+ $handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling');
52
+ $result = Mage::getModel('shipping/rate_result');
53
+
54
+ if (!$error && $price > 0) {
55
+ $method = Mage::getModel('shipping/rate_result_method');
56
+
57
+ $method->setCarrier($this->_code);
58
+ $method->setMethod($this->_code);
59
+ $method->setCarrierTitle($this->getConfigData('title'));
60
+ $method->setMethodTitle($methodTitle);
61
+ $method->setPrice($price);
62
+ $method->setCost($price);
63
+
64
+ $result->append($method);
65
+ } else {
66
+ $error = Mage::getModel('shipping/rate_result_error');
67
+
68
+ $error->setCarrier($this->_code);
69
+ $error->setCarrierTitle($this->getConfigData('title'));
70
+ $error->setErrorMessage($errorMessage);
71
+
72
+ $result->append($error);
73
+
74
+ if ($skynetErrorMessage) {
75
+ $helper->log($skynetErrorMessage, '', 'skynet_rate_request');
76
+ }
77
+ }
78
+
79
+ return $result;
80
+ }
81
+
82
+ public function getAllowedMethods()
83
+ {
84
+ return array($this->_code => $this->getConfigData('name'));
85
+ }
86
+
87
+ public function isTrackingAvailable()
88
+ {
89
+ return $this->getConfigData('tracking_service');
90
+ }
91
+
92
+ public function isShippingLabelsAvailable()
93
+ {
94
+ return false;
95
+ }
96
+
97
+ public function isCityRequired()
98
+ {
99
+ return false;
100
+ }
101
+
102
+ public function isZipCodeRequired($countryId = null)
103
+ {
104
+ if ($countryId != null) {
105
+ return !Mage::helper('directory')->isZipCodeOptional($countryId);
106
+ }
107
+
108
+ return true;
109
+ }
110
+
111
+ public function isGirthAllowed($countyDest = null)
112
+ {
113
+ return false;
114
+ }
115
+
116
+ protected function _updateFreeMethodQuote($request)
117
+ {
118
+ $freeShipping = false;
119
+ $items = $request->getAllItems();
120
+ $c = count($items);
121
+
122
+ for ($i = 0; $i < $c; $i++) {
123
+ if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) {
124
+ if ($items[$i]->getFreeShipping()) {
125
+ $freeShipping = true;
126
+ } else {
127
+ return;
128
+ }
129
+ }
130
+ }
131
+
132
+ if ($freeShipping) {
133
+ $request->setFreeShipping(true);
134
+ }
135
+ }
136
+ }
app/code/community/Shopgo/SkynetShipping/Model/Resource/Service.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Resource_Service extends Mage_Core_Model_Resource_Db_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('skynetshipping/service', 'service_id');
8
+ }
9
+
10
+ public function truncate()
11
+ {
12
+ $this->_getWriteAdapter()->query('TRUNCATE TABLE ' . $this->getMainTable());
13
+
14
+ Mage::getConfig()->deleteConfig(
15
+ Shopgo_SkynetShipping_Helper_Data::CARRIERS_SKYNET_SYSTEM_PATH . 'service'
16
+ );
17
+
18
+ return $this;
19
+ }
20
+ }
app/code/community/Shopgo/SkynetShipping/Model/Resource/Service/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Resource_Service_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('skynetshipping/service');
9
+ }
10
+ }
app/code/community/Shopgo/SkynetShipping/Model/Service.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Service extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('skynetshipping/service');
9
+ }
10
+
11
+ public function getList($params)
12
+ {
13
+ $helper = Mage::helper('skynetshipping');
14
+
15
+ $data = array(
16
+ 'UserName' => $params['username'],
17
+ 'Password' => $params['password'],
18
+ 'StationCode' => $params['station_code'],
19
+ 'ConsignorAccount' => $params['consignor_account']
20
+ );
21
+
22
+ $result = array(
23
+ 'status' => 0,
24
+ 'description' => $helper->__('An error has occurred. Please, contact the store administrator.')
25
+ );
26
+
27
+ $soapResult = $helper->soapClient('get_service_list', $data);
28
+
29
+ $debugLog = array(
30
+ array('message' => $helper->hideLogPrivacies($data)),
31
+ array('message' => $soapResult)
32
+ );
33
+
34
+ $helper->debug($debugLog, 'skynet_service_list');
35
+
36
+ if ($soapResult != '[soapfault]') {
37
+ $response = $helper->parseXmlResponse($soapResult, 'get_service_list');
38
+
39
+ if (false === strpos($response['status'], 'ERR')) {
40
+ $this->_saveServiceData($response['service_list']);
41
+
42
+ $list = Mage::getModel('skynetshipping/system_config_source_service')
43
+ ->toOptionArray();
44
+
45
+ $result = array(
46
+ 'status' => 1,
47
+ 'description' => $helper->__('Service list has been retrieved successfully!'),
48
+ 'list' => $list
49
+ );
50
+ } else {
51
+ $result['description'] = $response['status_description'];
52
+ }
53
+ }
54
+
55
+ return $result;
56
+ }
57
+
58
+ public function getServiceText($value)
59
+ {
60
+ $text = '';
61
+ $collection = Mage::getModel('skynetshipping/service')->getCollection();
62
+
63
+ foreach ($collection as $item) {
64
+ if ($value == $item->getServiceId()) {
65
+ $text = $item->getService();
66
+ break;
67
+ }
68
+ }
69
+
70
+ return $text;
71
+ }
72
+
73
+ private function _saveServiceData($data)
74
+ {
75
+ Mage::getResourceModel('skynetshipping/service')->truncate();
76
+
77
+ $model = Mage::getModel('skynetshipping/service');
78
+
79
+ foreach ($data as $i) {
80
+ $model->setService($i);
81
+ }
82
+
83
+ $model->save();
84
+ }
85
+ }
app/code/community/Shopgo/SkynetShipping/Model/Shipment.php ADDED
@@ -0,0 +1,512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Shipment extends Mage_Core_Model_Abstract
4
+ {
5
+ const POUNDS = 'LB';
6
+ const KILOGRAMS = 'KG';
7
+ const CUBIC_CENTIMETER = 'cm3';
8
+ const CUBIC_INCH = 'inch3';
9
+
10
+
11
+ public function getCode($type, $code = '')
12
+ {
13
+ $helper = Mage::helper('skynetshipping');
14
+
15
+ $codes = array(
16
+ 'unit_of_measure' => array(
17
+ self::POUNDS => $helper->__('Pounds'),
18
+ self::KILOGRAMS => $helper->__('Kilograms')
19
+ ),
20
+ 'unit_of_volume' => array(
21
+ self::CUBIC_CENTIMETER => $helper->__(self::CUBIC_CENTIMETER),
22
+ self::CUBIC_INCH => $helper->__(self::CUBIC_INCH)
23
+ )
24
+ );
25
+
26
+ if (!isset($codes[$type])) {
27
+ return false;
28
+ } elseif ('' === $code) {
29
+ return $codes[$type];
30
+ }
31
+
32
+ $code = strtoupper($code);
33
+ if (!isset($codes[$type][$code])) {
34
+ return false;
35
+ } else {
36
+ return $codes[$type][$code];
37
+ }
38
+ }
39
+
40
+ public function isEnabled()
41
+ {
42
+ return Mage::helper('skynetshipping')
43
+ ->getConfigData('shipping_service', 'carriers_skynet');
44
+ }
45
+
46
+ public function verifyAccount($params)
47
+ {
48
+ $helper = Mage::helper('skynetshipping');
49
+
50
+ $data = array(
51
+ 'UserName' => $params['username'],
52
+ 'Password' => $params['password'],
53
+ 'StationCode' => $params['station_code'],
54
+ 'ConsignorAccount' => $params['consignor_account']
55
+ );
56
+
57
+ $result = array(
58
+ 'status' => 0,
59
+ 'description' => $helper->__('An error has occurred. Please, contact the store administrator.')
60
+ );
61
+
62
+ $soapResult = $helper->soapClient('verify_account', $data);
63
+
64
+ $debugLog = array(
65
+ array('message' => $helper->hideLogPrivacies($data)),
66
+ array('message' => $soapResult)
67
+ );
68
+
69
+ $helper->debug($debugLog);
70
+
71
+ if ($soapResult != '[soapfault]') {
72
+ $response = $helper->parseXmlResponse($soapResult, 'verify_account');
73
+
74
+ if (false === strpos($response['status'], 'ERR')) {
75
+ $result = array(
76
+ 'status' => 1,
77
+ 'description' => $helper->__('Valid Account'),
78
+ 'list' => $list
79
+ );
80
+ } else {
81
+ $result['description'] = $helper->__('Invalid Account. If the issue persists, please contact the store administrator.');
82
+ }
83
+ }
84
+
85
+ return $result;
86
+ }
87
+
88
+ public function calculateRate($quote)
89
+ {
90
+ $helper = Mage::helper('skynetshipping');
91
+
92
+ $requestData = $this->_getRateRequestData($quote);
93
+
94
+ $supplierInfo = $helper->getOriginSupplier();
95
+ $params = $helper->getClientInfo($supplierInfo);
96
+
97
+ $service = Mage::getModel('skynetshipping/service')->getServiceText(
98
+ $helper->getConfigData('service', 'carriers_skynet')
99
+ );
100
+
101
+ $params['TR'] = array(
102
+ 'CONSIGNORACCOUNT' => $params['ConsignorAccount'],
103
+ 'DESTINATIONCOUNTRYCODE' => strtoupper($requestData['country_code']),
104
+ 'DESTINATIONDELIVERYAREA' => ucwords(strtolower($requestData['state_or_province_code'])),
105
+ 'NOOFPIECES' => $requestData['qty'],
106
+ 'ORIGINCOUNTRYCODE' => $supplierInfo['country_code'],
107
+ 'PIECESOFSHIPMENT' => array(),
108
+ 'SERVICE' => $service,
109
+ 'STATIONCODE' => $params['StationCode']
110
+ );
111
+
112
+ $params['TR']['PIECESOFSHIPMENT'] = $requestData['pieces'];
113
+
114
+ $result = array(
115
+ 'currency' => Mage::app()->getStore()->getBaseCurrencyCode(),
116
+ 'price' => 0
117
+ );
118
+
119
+ $soapResult = $helper->soapClient('rate_request', $params);
120
+
121
+ $debugLog = array(
122
+ array('message' => $helper->hideLogPrivacies($params)),
123
+ array('message' => $soapResult)
124
+ );
125
+
126
+ $helper->debug($debugLog, 'skynet_rate_request');
127
+
128
+ if ($soapResult != '[soapfault]') {
129
+ $result = $helper->parseXmlResponse($soapResult, 'rate_request');
130
+
131
+ if (false === strpos($result['status'], 'ERR')) {
132
+ $conversion = $helper->convertRateCurrency($result['price'], $result['currency']);
133
+ $result['currency'] = $conversion['currency'];
134
+ $result['price'] = $conversion['price'];
135
+ }
136
+ } else {
137
+ $result['status'] = 'ERR';
138
+ }
139
+
140
+ return $result;
141
+ }
142
+
143
+ private function _getRateRequestData($quote)
144
+ {
145
+ $qty = 0;
146
+ $dmAttr = array();
147
+ $pieces = array(
148
+ 'Piece' => array()
149
+ );
150
+
151
+ $helper = Mage::helper('skynetshipping');
152
+
153
+ $shippingAddress = $quote->getShippingAddress()->getData();
154
+
155
+ $dwaCodes = $helper->getDwaCodes();
156
+
157
+ foreach ($quote->getAllVisibleItems() as $item) {
158
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
159
+ $qty += $item->getQty();
160
+
161
+ foreach ($helper->getDwaNames() as $attr) {
162
+ $_prodData = $product->getData($dwaCodes[$attr]);
163
+ $dmAttr[$attr] = !empty($_prodData) ? $_prodData : 1;
164
+ }
165
+
166
+ $weight = $item->getWeight();
167
+
168
+ for ($i = 0; $i < $item->getQty(); $i++) {
169
+ $pieces['Piece'][] = array(
170
+ 'HEIGHTINCENTIMETERS' => $dmAttr[Shopgo_ShippingCore_Helper_Abstract::HEIGHT],
171
+ 'LENGTHINCENTIMETERS' => $dmAttr[Shopgo_ShippingCore_Helper_Abstract::LENGTH],
172
+ 'WIDHTINCENTIMETERS' => $dmAttr[Shopgo_ShippingCore_Helper_Abstract::WIDTH],
173
+ 'WEIGHTINKGS' => $weight
174
+ );
175
+ }
176
+ }
177
+
178
+ $data = array(
179
+ 'country_code' => $shippingAddress['country_id'],
180
+ 'state_or_province_code' => $shippingAddress['region'],
181
+ 'qty' => $qty
182
+ );
183
+
184
+ $data['pieces'] = $pieces;
185
+
186
+ return $data;
187
+ }
188
+
189
+ public function getShipmentItemsData($shipment)
190
+ {
191
+ $data = array(
192
+ 'TOTALWEIGHT' => 0,
193
+ 'TOTALLENGTH' => 0,
194
+ 'TOTALWIDTH' => 0,
195
+ 'TOTALHEIGHT' => 0,
196
+ 'ITEMNAME' => array(),
197
+ 'SKYBILLITEMDESC' => array()
198
+ );
199
+
200
+ $dwaCodes = Mage::helper('skynetshipping')->getDwaCodes();
201
+
202
+ foreach ($shipment->getAllItems() as $item) {
203
+ $qty = $item->getQty();
204
+
205
+ if (($qty - $item->getQtyShipped()) == 0) {
206
+ continue;
207
+ }
208
+
209
+ $data['TOTALWEIGHT'] += $item->getWeight() * $qty;
210
+
211
+ $data['TOTALLENGTH'] +=
212
+ ($item->getData($dwaCodes[Shopgo_ShippingCore_Helper_Abstract::LENGTH]) * $qty) + 0;
213
+ $data['TOTALWIDTH'] +=
214
+ ($item->getData($dwaCodes[Shopgo_ShippingCore_Helper_Abstract::WIDTH]) * $qty) + 0;
215
+ $data['TOTALHEIGHT'] +=
216
+ ($item->getData($dwaCodes[Shopgo_ShippingCore_Helper_Abstract::HEIGHT]) * $qty) + 0;
217
+
218
+ $data['ITEMNAME'][] = $item->getName();
219
+
220
+ $data['SKYBILLITEMDESC'][] = array(
221
+ 'ITEMQTY' => $qty,
222
+ 'UNITPRICE' => $item->getBasePrice(),
223
+ 'CUSTOMCODE' => $item->getHsCode(),
224
+ 'ITEMDESC' => $item->getName(),
225
+ 'UNITPRICE' => $item->getPrice(),
226
+ 'MFGCOUNTRY' => $item->getCountryOfManufacture(),
227
+ 'ORIGINSTATIONID' => 0,
228
+ 'REASONFOREXPORT' => '',
229
+ 'SKYBILLITEMNO' => 0
230
+ );
231
+ }
232
+
233
+ return $data;
234
+ }
235
+
236
+ public function getShipmentData($shipment, $additionalData)
237
+ {
238
+ $helper = Mage::helper('skynetshipping');
239
+
240
+ $consignorData = $helper->getOriginSupplier();
241
+
242
+ $shipmentItemsData = $this->getShipmentItemsData($shipment);
243
+
244
+ $accountInfo = $helper->getClientInfo($consignorData);
245
+
246
+ $order = Mage::getModel('sales/order')->load($shipment->getOrder()->getId());
247
+
248
+ $consigneeData = $order->getShippingAddress()->getData();
249
+
250
+ if (empty($consigneeData['email'])) {
251
+ $consigneeData['email'] = $order->getCustomerEmail();
252
+ }
253
+
254
+ $consigneeName = !empty($consigneeData['company'])
255
+ ? $consigneeData['company']
256
+ : $consigneeData['firstname'] . ' ' . $consigneeData['lastname'];
257
+
258
+ $service = Mage::getModel('skynetshipping/service')->getServiceText(
259
+ $helper->getConfigData('service', 'carriers_skynet')
260
+ );
261
+
262
+ $contents = implode(',', $shipmentItemsData['ITEMNAME']);
263
+
264
+ if (strlen($contents) > 100) {
265
+ $contents = substr($contents, 0, 96) . '...';
266
+ }
267
+
268
+ $baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
269
+
270
+ $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($order->getQuoteId());
271
+
272
+ $calculatedWeights = $this->calculateRate($quote);
273
+
274
+ $valueAmount = $order->getBaseSubtotal();
275
+ $codAmount = 0;
276
+
277
+ $codMethods = $helper->getCodMethodList();
278
+
279
+ if ($helper->getConfigData('cod', 'carriers_skynet')
280
+ && in_array($order->getPayment()->getMethodInstance()->getCode(), $codMethods)) {
281
+ $codCurrency = $helper->getCodCurrency($order);
282
+ $codAmount = $helper->currencyConvert(
283
+ $order->getBaseGrandTotal(), $baseCurrencyCode,
284
+ $codCurrency, 'price', 2
285
+ );
286
+ }
287
+
288
+ $data = array(
289
+ 'SkybillObject' => array(
290
+ 'BILLDATE' => date('c', time()),
291
+
292
+ 'CONSIGNORACCOUNT' => $accountInfo['ConsignorAccount'],
293
+ 'CONSIGNOR' => $consignorData['consignor_name'],
294
+ 'CONSIGNORADDRESS' => $consignorData['address_line1'],
295
+ 'CONSIGNORCITY' => $consignorData['city'],
296
+ 'CONSIGNORCOUNTRY' => $consignorData['country_code'],
297
+ 'CONSIGNOREMAIL' => $consignorData['email'],
298
+ 'CONSIGNORFAX' => $consignorData['fax_number'],
299
+ 'CONSIGNORPHONE' => $consignorData['phone_number'],
300
+ 'CONSIGNORREF' => $additionalData['consignor_ref'],
301
+ 'CONSIGNORSTATE' => $consignorData['state_or_province_code'],
302
+ 'CONSIGNORZIPCODE' => $consignorData['zipcode'],
303
+
304
+ 'CONSIGNEE' => $consigneeName,
305
+ 'CONSIGNEEADDRESS' => $helper->getSingleLineStreetAddress($consigneeData['street']),
306
+ 'CONSIGNEECOUNTRY' => $consigneeData['country_id'],
307
+ 'CONSIGNEEEMAILADDRESS' => $consigneeData['email'],
308
+ 'CONSIGNEETOWN' => $consigneeData['city'],
309
+ 'CONSIGNEESTATE' => $consigneeData['region'],
310
+ 'CONSIGNEEZIPCODE' => $consigneeData['postcode'],
311
+ 'CONSIGNEETELEPHONE' => $consigneeData['telephone'],
312
+ 'CONSIGNEEATTENTION' => $consigneeData['firstname'] . ' ' . $consigneeData['lastname'],
313
+ 'CONSIGNEEFAX' => '',
314
+ 'CONSIGNEEMOBILE' => '',
315
+ 'CONSIGNEETAXID' => 0,
316
+
317
+ 'TYPEOFSHIPMENT' => $additionalData['type'],
318
+ 'SERVICES' => $service,
319
+ 'PIECES' => 1, // In our case, we will only have 1 SKYBILLITEM.
320
+ 'TOTALWEIGHT' => $shipmentItemsData['TOTALWEIGHT'],
321
+ 'VALUEAMT' => $valueAmount,
322
+ 'CURRENCY' => $baseCurrencyCode,
323
+ 'CODAMOUNT' => $codAmount,
324
+ 'CODCURRENCY' => $codCurrency,
325
+ 'DESTINATIONCODE' => '',
326
+ 'ORIGINSTATION' => $accountInfo['StationCode'],
327
+
328
+ 'TOTALVOLWEIGHT' => $calculatedWeights['vol_weight'],
329
+ 'CHARGABLEWEIGHT' => $calculatedWeights['charged_weight'],
330
+ 'CONTENTS' => $contents,
331
+ 'CONTRACTORNAME' => '',
332
+ 'CONTRACTORREF' => '',
333
+ 'NEWCONTENTS' => '',
334
+ 'ORIGINSTATIONID' => 0,
335
+ 'SKYBILLID' => 0,
336
+ 'SKYBILLNUMBER' => '',
337
+ 'SKYBILLPREFIX' => '',
338
+ 'TOSTATIONID' => 0,
339
+
340
+ 'SKYBILLITEMS' => array(
341
+ 'SKYBILLITEM' => array(array(
342
+ 'WEIGHT' => $shipmentItemsData['TOTALWEIGHT'],
343
+ 'VOLWEIGHT' => 0,
344
+ 'LEN' => $shipmentItemsData['TOTALLENGTH'],
345
+ 'WIDTH' => $shipmentItemsData['TOTALWIDTH'],
346
+ 'HEIGHT' => $shipmentItemsData['TOTALHEIGHT'],
347
+ 'DECLAREDWEIGHT' => 0,
348
+ 'ITEMDESCRIPTION' => '',
349
+ 'ITEMNO' => 0,
350
+ 'ORIGINSTATIONID' => 0,
351
+ 'SKYBILLID' => 0,
352
+ 'SkybillItemDescs' => array(
353
+ 'SKYBILLITEMDESC' => $shipmentItemsData['SKYBILLITEMDESC']
354
+ )
355
+ ))
356
+ )
357
+ )
358
+ );
359
+
360
+ $data = array_merge($data, $accountInfo);
361
+
362
+ return $data;
363
+ }
364
+
365
+ public function prepareShipment($shipment, $additionalData)
366
+ {
367
+ $result = false;
368
+
369
+ $order = Mage::getModel('sales/order')
370
+ ->load($shipment->getOrder()->getId());
371
+
372
+ if ($this->isEnabled() && $order->canShip()) {
373
+ $result = $this->_createShipment($shipment, $additionalData);
374
+ }
375
+
376
+ return $result;
377
+ }
378
+
379
+ private function _createShipment($shipment, $additionalData)
380
+ {
381
+ $helper = Mage::helper('skynetshipping');
382
+
383
+ $result = false;
384
+ $shipmentData = $this->getShipmentData($shipment, $additionalData['shipment']);
385
+
386
+ $soapResult = $helper->soapClient(
387
+ 'create_shipment',
388
+ $shipmentData
389
+ );
390
+
391
+ if ($soapResult != '[soapfault]') {
392
+ $result = $helper->parseXmlResponse($soapResult, 'shipping_service');
393
+
394
+ $debugLog = array(
395
+ array('message' => $helper->hideLogPrivacies($shipmentData)),
396
+ array('message' => $result)
397
+ );
398
+
399
+ $helper->debug($debugLog, 'skynet_create_shipment');
400
+
401
+ if (false === strpos($result['status'], 'ERR')) {
402
+ $result = $this->_saveShipment($shipment, $result, 0);
403
+ } else {
404
+ $helper->log($result['status_description'], '', 'skynet_create_shipment');
405
+ $userMsg = $helper->__(
406
+ 'Shipment could not be created, please contact us to know more about this issue.<br/>Error:&nbsp;%s',
407
+ $result['status_description']
408
+ );
409
+ $helper->userMessage($userMsg, 'error');
410
+
411
+ $result = false;
412
+ }
413
+ } else {
414
+ $debugLog = array(
415
+ array('message' => $helper->hideLogPrivacies($shipmentData)),
416
+ array('message' => $soapResult)
417
+ );
418
+
419
+ $helper->debug($debugLog, 'skynet_create_shipment');
420
+ }
421
+
422
+ return $result;
423
+ }
424
+
425
+ private function _saveShipment($shipment, $shipmentData, $trackingNo = null)
426
+ {
427
+ $helper = Mage::helper('skynetshipping');
428
+ $result = false;
429
+
430
+ try {
431
+ $comments = array(
432
+ 'shipment_number' =>
433
+ sprintf(
434
+ '<strong>' . $helper->__('Shipment No.') . ':</strong>&nbsp;%s',
435
+ $shipmentData['shipment_number']
436
+ ),
437
+ 'request_id' =>
438
+ sprintf(
439
+ '<strong>' . $helper->__('Request ID') . ':</strong>&nbsp;%s',
440
+ $shipmentData['request_id']
441
+ ),
442
+ 'shipping_label' =>
443
+ sprintf(
444
+ '<strong>' . $helper->__('Shipping Label') . ':</strong>&nbsp;%s%s',
445
+ 'https://www.skynetwwe.info/Reports/AWBPrint.aspx?Skybill=',
446
+ $shipmentData['shipment_number']
447
+ )
448
+ );
449
+
450
+ foreach ($comments as $comment) {
451
+ $shipment->addComment($comment, false, false);
452
+ }
453
+
454
+ $order = $shipment->getOrder();
455
+
456
+ $order->setIsInProcess(true);
457
+
458
+ $transactionSave = Mage::getModel('core/resource_transaction')
459
+ ->addObject($shipment)
460
+ ->addObject($order)
461
+ ->save();
462
+
463
+ $comments = '<br/><br/>' . implode('<br/>', $comments);
464
+
465
+ $this->_sendShipmentEmail($shipment, $comments);
466
+
467
+ $result = true;
468
+ } catch (Exception $e) {
469
+ $helper->log($e, 'exception');
470
+ $helper->log(
471
+ array('message' => $helper->__('Shipment could not be created (Saved), check exception log.')),
472
+ '', 'skynet_create_shipment'
473
+ );
474
+
475
+ $helper->userMessage(
476
+ $helper->__('Shipment could not be created, please contact us to look into the issue.'), 'error'
477
+ );
478
+ }
479
+
480
+ return $result;
481
+ }
482
+
483
+ private function _sendShipmentEmail($shipment, $comments)
484
+ {
485
+ $helper = Mage::helper('skynetshipping');
486
+ $result = false;
487
+
488
+ try {
489
+ if ($shipment->getOrder()->getCustomerEmail() && !$shipment->getEmailSent()) {
490
+ $comments = '<br/><strong>' . $helper->__('Comments') . ':</strong>'
491
+ . $comments;
492
+
493
+ $shipment->sendEmail(true, $comments);
494
+ $shipment->setEmailSent(true);
495
+
496
+ $result = true;
497
+ }
498
+ } catch (Exception $e) {
499
+ $helper->log($e, 'exception');
500
+ $helper->log(
501
+ array('message' => $helper->__('Shipment email could not be sent, check exception log.')),
502
+ '', 'skynet_create_shipment'
503
+ );
504
+
505
+ $helper->userMessage(
506
+ $helper->__('Shipment email could not be sent, please contact us to look into the issue.'), 'error'
507
+ );
508
+ }
509
+
510
+ return $result;
511
+ }
512
+ }
app/code/community/Shopgo/SkynetShipping/Model/Shipment/Source/Typeofshipment.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_Shipment_Source_Typeofshipment
4
+ {
5
+ public function toOptionArray($pleaseSelect = false)
6
+ {
7
+ $helper = Mage::helper('skynetshipping');
8
+
9
+ $options = array(
10
+ array('label' => $helper->__('NON DOCS'),
11
+ 'value' => 'NON DOCS'),
12
+ array('label' => $helper->__('DOCS'),
13
+ 'value' => 'DOCS'),
14
+ array('label' => $helper->__('DOCS & NON'),
15
+ 'value' => 'DOCS & NON')
16
+ );
17
+
18
+ if ($pleaseSelect) {
19
+ array_unshift(
20
+ $options,
21
+ array('label' => $helper->__('- Please Select -'),
22
+ 'value' => ''
23
+ )
24
+ );
25
+ }
26
+
27
+ return $options;
28
+ }
29
+ }
app/code/community/Shopgo/SkynetShipping/Model/System/Config/Source/Service.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Model_System_Config_Source_Service
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $options = array();
8
+ $collection = Mage::getModel('skynetshipping/service')->getCollection();
9
+
10
+ foreach ($collection as $item) {
11
+ $options[] = array(
12
+ 'label' => $item['service'],
13
+ 'value' => $item['service_id']
14
+ );
15
+ }
16
+
17
+ if (empty($options)) {
18
+ $options[] = array(
19
+ 'label' => Mage::helper('skynetshipping')->__('- No Services Available -'),
20
+ 'value' => ''
21
+ );
22
+ } else {
23
+ array_unshift(
24
+ $options,
25
+ array(
26
+ 'label' => Mage::helper('skynetshipping')->__('--Please Select--'),
27
+ 'value' => ''
28
+ )
29
+ );
30
+ }
31
+
32
+ return $options;
33
+ }
34
+ }
app/code/community/Shopgo/SkynetShipping/controllers/Adminhtml/SkynetController.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Shopgo_SkynetShipping_Adminhtml_SkynetController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ public function verifyAccountAction()
6
+ {
7
+ $params = $this->getRequest()->getPost();
8
+ $helper = Mage::helper('skynetshipping');
9
+ $response = Mage::app()->getResponse()
10
+ ->setHeader('content-type', 'application/json; charset=utf-8');
11
+
12
+ $result = array(
13
+ 'status' => 0,
14
+ 'description' => $this->__('An error has occurred. Please, contact the store administrator.')
15
+ );
16
+
17
+ $clientInfo = $helper->getOriginSupplier('skynet_account');
18
+
19
+ foreach ($clientInfo as $key => $val) {
20
+ if (empty($params[$key]) && $params[$key] !== 0) {
21
+ $result['description'] = $this->__(
22
+ 'Username, Password, Station Code and Consignor Account are required in order to verify your account'
23
+ );
24
+ $response->setBody(json_encode($result));
25
+
26
+ return;
27
+ }
28
+ }
29
+
30
+ if (!$params['username_changed'] && $params['username'] == '******') {
31
+ $params['username'] = $helper->getConfigData('username', 'carriers_skynet');
32
+ $params['username'] = Mage::helper('core')->decrypt($params['username']);
33
+ }
34
+
35
+ if (!$params['password_changed'] && $params['password'] == '******') {
36
+ $params['password'] = $helper->getConfigData('password', 'carriers_skynet');
37
+ $params['password'] = Mage::helper('core')->decrypt($params['password']);
38
+ }
39
+
40
+ $result = Mage::getModel('skynetshipping/shipment')->verifyAccount($params);
41
+
42
+ $response->setBody(json_encode($result));
43
+ }
44
+
45
+ public function getServiceListAction()
46
+ {
47
+ $params = $this->getRequest()->getPost();
48
+ $helper = Mage::helper('skynetshipping');
49
+ $response = Mage::app()->getResponse()
50
+ ->setHeader('content-type', 'application/json; charset=utf-8');
51
+
52
+ $result = array(
53
+ 'status' => 0,
54
+ 'description' => $this->__('An error has occurred. Please, contact the store administrator.')
55
+ );
56
+
57
+ $validValues = array(
58
+ 'username_changed' => array(0, 1),
59
+ 'password_changed' => array(0, 1)
60
+ );
61
+
62
+ if (!isset($params['username_changed']) || !isset($params['password_changed'])) {
63
+ $result['description'] = $this->__('Bad request');
64
+ $response->setBody(json_encode($result));
65
+
66
+ return;
67
+ } elseif (!in_array($params['username_changed'], $validValues['username_changed'])
68
+ || !in_array($params['password_changed'], $validValues['password_changed'])) {
69
+ $result['description'] = $this->__('Bad request');
70
+ $response->setBody(json_encode($result));
71
+
72
+ return;
73
+ }
74
+
75
+ foreach ($params as $p) {
76
+ if (empty($p) && $p != 0) {
77
+ $result['description'] = $this->__(
78
+ 'Username, Password, Station Code and Consignee Number are necessary in order to get services list'
79
+ );
80
+ $response->setBody(json_encode($result));
81
+
82
+ return;
83
+ }
84
+ }
85
+
86
+ if (!$params['username_changed'] && $params['username'] == '******') {
87
+ $params['username'] = $helper->getConfigData('username', 'carriers_skynet');
88
+ $params['username'] = Mage::helper('core')->decrypt($params['username']);
89
+ }
90
+
91
+ if (!$params['password_changed'] && $params['password'] == '******') {
92
+ $params['password'] = $helper->getConfigData('password', 'carriers_skynet');
93
+ $params['password'] = Mage::helper('core')->decrypt($params['password']);
94
+ }
95
+
96
+ $result = Mage::getModel('skynetshipping/service')->getList($params);
97
+
98
+ $response->setBody(json_encode($result));
99
+ }
100
+ }
app/code/community/Shopgo/SkynetShipping/etc/config.xml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shopgo_SkynetShipping>
5
+ <version>1.0.7</version>
6
+ </Shopgo_SkynetShipping>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <skynetshipping>
11
+ <class>Shopgo_SkynetShipping_Block</class>
12
+ </skynetshipping>
13
+ </blocks>
14
+ <helpers>
15
+ <skynetshipping>
16
+ <class>Shopgo_SkynetShipping_Helper</class>
17
+ </skynetshipping>
18
+ </helpers>
19
+ <models>
20
+ <skynetshipping>
21
+ <class>Shopgo_SkynetShipping_Model</class>
22
+ <resourceModel>skynetshipping_resource</resourceModel>
23
+ </skynetshipping>
24
+ <skynetshipping_resource>
25
+ <class>Shopgo_SkynetShipping_Model_Resource</class>
26
+ <entities>
27
+ <service>
28
+ <table>sg_skynet_shipping_service</table>
29
+ </service>
30
+ </entities>
31
+ </skynetshipping_resource>
32
+ </models>
33
+ <resources>
34
+ <skynetshipping_setup>
35
+ <setup>
36
+ <module>Shopgo_SkynetShipping</module>
37
+ </setup>
38
+ <connection>
39
+ <use>core_setup</use>
40
+ </connection>
41
+ </skynetshipping_setup>
42
+ <skynetshipping_write>
43
+ <connection>
44
+ <use>core_write</use>
45
+ </connection>
46
+ </skynetshipping_write>
47
+ <skynetshipping_read>
48
+ <connection>
49
+ <use>core_read</use>
50
+ </connection>
51
+ </skynetshipping_read>
52
+ </resources>
53
+ </global>
54
+ <admin>
55
+ <routers>
56
+ <adminhtml>
57
+ <args>
58
+ <modules>
59
+ <skynetshipping before="Mage_Adminhtml">Shopgo_SkynetShipping_Adminhtml</skynetshipping>
60
+ </modules>
61
+ </args>
62
+ </adminhtml>
63
+ </routers>
64
+ </admin>
65
+ <adminhtml>
66
+ <layout>
67
+ <updates>
68
+ <skynetshipping>
69
+ <file>shopgo/skynet_shipping.xml</file>
70
+ </skynetshipping>
71
+ </updates>
72
+ </layout>
73
+ </adminhtml>
74
+ <default>
75
+ <carriers>
76
+ <skynet>
77
+ <active>0</active>
78
+ <model>skynetshipping/carrier_skynet</model>
79
+ <title>Skynet Worldwide Express</title>
80
+ <unit_of_measure>KG</unit_of_measure>
81
+ <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
82
+ </skynet>
83
+ </carriers>
84
+ </default>
85
+ </config>
app/code/community/Shopgo/SkynetShipping/etc/system.xml ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <carriers>
5
+ <groups>
6
+ <skynet translate="label" module="skynetshipping">
7
+ <label>SkyNet</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>99</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Enabled for Checkout</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ </active>
23
+ <title translate="label">
24
+ <label>Title</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>20</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </title>
31
+ <username translate="label">
32
+ <label>User Name</label>
33
+ <frontend_type>obscure</frontend_type>
34
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
35
+ <sort_order>30</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </username>
40
+ <password translate="label">
41
+ <label>Password</label>
42
+ <comment><![CDATA[
43
+ You can create your SkyNet account from here:<br/>
44
+ https://ws01.ffdx.net/v4/login.aspx?stid=skynet#
45
+ ]]></comment>
46
+ <frontend_type>obscure</frontend_type>
47
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_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
+ </password>
53
+ <station_code translate="label">
54
+ <label>Station Code</label>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>50</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>0</show_in_store>
60
+ </station_code>
61
+ <consignor_account translate="label">
62
+ <label>Consignor Account</label>
63
+ <frontend_type>text</frontend_type>
64
+ <sort_order>60</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>0</show_in_store>
68
+ </consignor_account>
69
+ <check_account translate="label">
70
+ <frontend_type>button</frontend_type>
71
+ <frontend_model>skynetshipping/adminhtml_system_config_form_verifyAccountButton</frontend_model>
72
+ <sort_order>70</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>1</show_in_website>
75
+ <show_in_store>0</show_in_store>
76
+ </check_account>
77
+ <service translate="label">
78
+ <label>Service</label>
79
+ <frontend_type>select</frontend_type>
80
+ <source_model>skynetshipping/system_config_source_service</source_model>
81
+ <sort_order>80</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>0</show_in_store>
85
+ </service>
86
+ <service_getter translate="label">
87
+ <frontend_type>button</frontend_type>
88
+ <frontend_model>skynetshipping/adminhtml_system_config_form_serviceListButton</frontend_model>
89
+ <sort_order>90</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>1</show_in_website>
92
+ <show_in_store>0</show_in_store>
93
+ </service_getter>
94
+ <cod translate="label">
95
+ <label>Cash on Delivery</label>
96
+ <frontend_type>select</frontend_type>
97
+ <sort_order>100</sort_order>
98
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>0</show_in_store>
102
+ </cod>
103
+ <shipping_service translate="label">
104
+ <label>Shipping Service</label>
105
+ <comment>If disabled, SkyNet shipping service will not be used to register SkyNet shipments, whenever a store shipment is created.</comment>
106
+ <frontend_type>select</frontend_type>
107
+ <sort_order>110</sort_order>
108
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>0</show_in_store>
112
+ </shipping_service>
113
+ <free_shipping_enable translate="label">
114
+ <label>Free Shipping with Minimum Order Amount</label>
115
+ <frontend_type>select</frontend_type>
116
+ <source_model>adminhtml/system_config_source_enabledisable</source_model>
117
+ <sort_order>120</sort_order>
118
+ <show_in_default>1</show_in_default>
119
+ <show_in_website>1</show_in_website>
120
+ <show_in_store>0</show_in_store>
121
+ </free_shipping_enable>
122
+ <free_shipping_subtotal translate="label">
123
+ <label>Minimum Order Amount for Free Shipping</label>
124
+ <frontend_type>text</frontend_type>
125
+ <validate>validate-number validate-zero-or-greater</validate>
126
+ <sort_order>130</sort_order>
127
+ <show_in_default>1</show_in_default>
128
+ <show_in_website>1</show_in_website>
129
+ <show_in_store>0</show_in_store>
130
+ <depends><free_shipping_enable>1</free_shipping_enable></depends>
131
+ </free_shipping_subtotal>
132
+ <specificerrmsg translate="label">
133
+ <label>Displayed Error Message</label>
134
+ <comment>If specified, it will replace some of the system's default messages.</comment>
135
+ <frontend_type>textarea</frontend_type>
136
+ <sort_order>140</sort_order>
137
+ <show_in_default>1</show_in_default>
138
+ <show_in_website>1</show_in_website>
139
+ <show_in_store>1</show_in_store>
140
+ </specificerrmsg>
141
+ <sallowspecific translate="label">
142
+ <label>Ship to Applicable Countries</label>
143
+ <frontend_type>select</frontend_type>
144
+ <sort_order>150</sort_order>
145
+ <frontend_class>shipping-applicable-country</frontend_class>
146
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
147
+ <show_in_default>1</show_in_default>
148
+ <show_in_website>1</show_in_website>
149
+ <show_in_store>0</show_in_store>
150
+ </sallowspecific>
151
+ <specificcountry translate="label">
152
+ <label>Ship to Specific Countries</label>
153
+ <frontend_type>multiselect</frontend_type>
154
+ <sort_order>160</sort_order>
155
+ <source_model>adminhtml/system_config_source_country</source_model>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>0</show_in_store>
159
+ <can_be_empty>1</can_be_empty>
160
+ </specificcountry>
161
+ <debug translate="label">
162
+ <label>Debug</label>
163
+ <comment>Make sure that system logging is enabled (System > Configuration > Advanced > Developer > Log Settings) in order to use this feature.</comment>
164
+ <frontend_type>select</frontend_type>
165
+ <sort_order>170</sort_order>
166
+ <source_model>adminhtml/system_config_source_yesno</source_model>
167
+ <show_in_default>1</show_in_default>
168
+ <show_in_website>1</show_in_website>
169
+ <show_in_store>0</show_in_store>
170
+ </debug>
171
+ <showmethod translate="label">
172
+ <label>Show Method if Not Applicable</label>
173
+ <frontend_type>select</frontend_type>
174
+ <sort_order>180</sort_order>
175
+ <frontend_class>shipping-skip-hide</frontend_class>
176
+ <source_model>adminhtml/system_config_source_yesno</source_model>
177
+ <show_in_default>1</show_in_default>
178
+ <show_in_website>1</show_in_website>
179
+ <show_in_store>0</show_in_store>
180
+ </showmethod>
181
+ <skynet_error translate="label">
182
+ <label>Show Skynet errors</label>
183
+ <frontend_type>select</frontend_type>
184
+ <sort_order>190</sort_order>
185
+ <frontend_class>shipping-skip-hide</frontend_class>
186
+ <source_model>adminhtml/system_config_source_yesno</source_model>
187
+ <show_in_default>1</show_in_default>
188
+ <show_in_website>1</show_in_website>
189
+ <show_in_store>0</show_in_store>
190
+ <depends><showmethod>1</showmethod></depends>
191
+ </skynet_error>
192
+ <sort_order translate="label">
193
+ <label>Sort Order</label>
194
+ <frontend_type>text</frontend_type>
195
+ <sort_order>200</sort_order>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <show_in_store>0</show_in_store>
199
+ </sort_order>
200
+ </fields>
201
+ </skynet>
202
+ </groups>
203
+ </carriers>
204
+ <shipping translate="label" module="skynetshipping">
205
+ <groups>
206
+ <skynet_settings translate="label">
207
+ <label>SkyNet Shipping Settings</label>
208
+ <frontend_type>text</frontend_type>
209
+ <sort_order>7</sort_order>
210
+ <show_in_default>1</show_in_default>
211
+ <show_in_website>1</show_in_website>
212
+ <show_in_store>1</show_in_store>
213
+ <fields>
214
+ <consignor_name translate="label">
215
+ <label>Consignor Name</label>
216
+ <frontend_type>text</frontend_type>
217
+ <sort_order>10</sort_order>
218
+ <show_in_default>1</show_in_default>
219
+ <show_in_website>1</show_in_website>
220
+ <show_in_store>0</show_in_store>
221
+ </consignor_name>
222
+ </fields>
223
+ </skynet_settings>
224
+ </groups>
225
+ </shipping>
226
+ </sections>
227
+ </config>
app/code/community/Shopgo/SkynetShipping/sql/skynetshipping_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ /**
8
+ * Create table 'sg_skynet_shipping_service'
9
+ */
10
+ $table = $installer->getConnection()
11
+ ->newTable($installer->getTable('skynetshipping/service'))
12
+ ->addColumn('service_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
13
+ 'identity' => true,
14
+ 'unsigned' => true,
15
+ 'nullable' => false,
16
+ 'primary' => true,
17
+ ), 'Service ID')
18
+ ->addColumn('service', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
19
+ 'nullable' => false
20
+ ), 'Service Name')
21
+ ->setComment('Services');
22
+
23
+ $installer->getConnection()->createTable($table);
24
+
25
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/shopgo/skynet_shipping.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_sales_order_shipment_new>
4
+ <reference name="head">
5
+ <action method="addCss" ifconfig="carriers/skynet/shipping_service">
6
+ <name>shopgo/skynet_shipping/sales/order/shipment/create/form/css/main.css</name>
7
+ <adv_ifconfig>
8
+ <required_depends>carriers/skynet/active</required_depends>
9
+ <depends_check>1</depends_check>
10
+ <custom_rules>
11
+ <check_used_method>skynet</check_used_method>
12
+ </custom_rules>
13
+ </adv_ifconfig>
14
+ </action>
15
+ <action method="addCss" ifconfig="carriers/skynet/shipping_service">
16
+ <name>shopgo/skynet_shipping/sales/order/shipment/create/form/css/shipment.css</name>
17
+ <adv_ifconfig>
18
+ <required_depends>carriers/skynet/active</required_depends>
19
+ <depends_check>1</depends_check>
20
+ <custom_rules>
21
+ <check_used_method>skynet</check_used_method>
22
+ </custom_rules>
23
+ </adv_ifconfig>
24
+ </action>
25
+ </reference>
26
+ <reference name="form">
27
+ <block
28
+ type="skynetshipping/adminhtml_sales_order_shipment_create_form_shipment"
29
+ name="skynet_shipment"
30
+ template="shopgo/skynet_shipping/sales/order/shipment/create/form/shipment.phtml"
31
+ />
32
+ </reference>
33
+ </adminhtml_sales_order_shipment_new>
34
+ </layout>
app/design/adminhtml/default/default/template/shopgo/skynet_shipping/sales/order/shipment/create/form/shipment.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($this->isEnabled()): ?>
2
+ <?php $formData = $this->getFormData() ?>
3
+ <div class="entry-edit">
4
+ <div class="entry-edit-head">
5
+ <h4 class="icon-head head-shopgo-skynet-shipment"><?php echo Mage::helper('sales')->__('SkyNet Shipment Create Form') ?></h4>
6
+ <div class="clear"></div>
7
+ </div>
8
+ <div id="shopgo_skynet_shipment_container" class="shopgo-skynet-container-table">
9
+ <fieldset>
10
+ <div class="row">
11
+ <div><strong><?php echo $this->__('Shipment Details') ?></strong></div>
12
+ <div class="fieldset shipment-details">
13
+ <div class="box-left">
14
+ <table id="shopgo_skynet_shipment_details_table_left" cellpadding="0" cellspacing="0">
15
+ <tbody>
16
+ <tr class="type">
17
+ <td class="label"><?php echo $this->__('Type of Shipment') ?></td>
18
+ <td class="field">
19
+ <select name="shopgo[skynet][shipment][type]">
20
+ <?php $shipmentType = $formData['type_of_shipment'] ?>
21
+ <?php foreach ($this->getShipmentTypeOptions() as $option): ?>
22
+ <option value="<?php echo $option['value'] ?>"<?php if ($shipmentType == $option['value']): ?> selected<?php endif ?>><?php echo $option['label'] ?></option>
23
+ <?php endforeach ?>
24
+ </select>
25
+ </td>
26
+ </tr>
27
+ </tbody>
28
+ </table>
29
+ </div>
30
+ <div class="box-right">
31
+ <table id="shopgo_skynet_shipment_details_table_right" cellpadding="0" cellspacing="0">
32
+ <tbody>
33
+ <tr class="consignor-ref">
34
+ <td class="label"><?php echo $this->__('Consignor Reference') ?></td>
35
+ <td class="field">
36
+ <input type="text" class="input-text" name="shopgo[skynet][shipment][consignor_ref]" value="<?php echo $this->getFormFieldData('consignor_ref', $formData['consignor_ref']) ?>" />
37
+ </td>
38
+ </tr>
39
+ </tbody>
40
+ </table>
41
+ </div>
42
+ <div class="clear"></div>
43
+ </div>
44
+ </div>
45
+ </fieldset>
46
+ </div>
47
+ </div>
48
+ <?php endif ?>
app/design/adminhtml/default/default/template/shopgo/skynet_shipping/system/config/service_list_button.phtml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getButtonHtml() ?>
2
+ <script type="text/javascript">//<![CDATA[
3
+ if (typeof shopgo == 'undefined') {
4
+ var shopgo = new Object();
5
+ }
6
+ if (typeof shopgo.skynetShipping == 'undefined') {
7
+ shopgo.skynetShipping = new Object();
8
+ }
9
+
10
+ shopgo.skynetShipping.serviceListButton = {
11
+ usernameChanged: 0,
12
+ passwordChanged: 0,
13
+ elmClassPrefix: 'carriers_skynet_',
14
+ getList: function() {
15
+ var _params = {
16
+ username: $(this.elmClassPrefix + 'username').value,
17
+ password: $(this.elmClassPrefix + 'password').value,
18
+ station_code: $(this.elmClassPrefix + 'station_code').value,
19
+ consignor_account: $(this.elmClassPrefix + 'consignor_account').value,
20
+ username_changed: this.usernameChanged,
21
+ password_changed: this.passwordChanged
22
+ };
23
+
24
+ new Ajax.Request('<?php echo $this->getAjaxActionUrl() ?>', {
25
+ parameters: _params,
26
+ onSuccess: function(transport) {
27
+ if (transport.responseText) {
28
+ var response = transport.responseText.evalJSON(true);
29
+
30
+ if (response.status) {
31
+ var listElm = $(shopgo.skynetShipping.serviceListButton.elmClassPrefix + 'service');
32
+
33
+ listElm.select('option').invoke('remove');
34
+
35
+ response.list.forEach(function(element, index, array) {
36
+ listElm.insert(
37
+ new Element('option', {value: element.value}).update(element.label)
38
+ );
39
+ });
40
+ }
41
+
42
+ alert(response.description);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ };
48
+
49
+ document.observe("dom:loaded", function() {
50
+ $(shopgo.skynetShipping.serviceListButton.elmClassPrefix + 'username').observe(
51
+ 'change', function(event) {
52
+ shopgo.skynetShipping.serviceListButton.usernameChanged = 1;
53
+ }
54
+ );
55
+ $(shopgo.skynetShipping.serviceListButton.elmClassPrefix + 'password').observe(
56
+ 'change', function(event) {
57
+ shopgo.skynetShipping.serviceListButton.passwordChanged = 1;
58
+ }
59
+ );
60
+ });
61
+ //]]></script>
app/design/adminhtml/default/default/template/shopgo/skynet_shipping/system/config/verify_account_button.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getButtonHtml() ?>
2
+ <script type="text/javascript">//<![CDATA[
3
+ if (typeof shopgo == 'undefined') {
4
+ var shopgo = new Object();
5
+ }
6
+ if (typeof shopgo.skynetShipping == 'undefined') {
7
+ shopgo.skynetShipping = new Object();
8
+ }
9
+
10
+ shopgo.skynetShipping.verifyAccountButton = {
11
+ usernameChanged: 0,
12
+ passwordChanged: 0,
13
+ elmClassPrefix: 'carriers_skynet_',
14
+ verifyAccount: function() {
15
+ var _params = {
16
+ username: $(this.elmClassPrefix + 'username').value,
17
+ password: $(this.elmClassPrefix + 'password').value,
18
+ station_code: $(this.elmClassPrefix + 'station_code').value,
19
+ consignor_account: $(this.elmClassPrefix + 'consignor_account').value,
20
+ username_changed: this.usernameChanged,
21
+ password_changed: this.passwordChanged
22
+ };
23
+ new Ajax.Request('<?php echo $this->getAjaxVerifyAccountUrl() ?>', {
24
+ parameters: _params,
25
+ onSuccess: function(transport) {
26
+ if (transport.responseText) {
27
+ var response = transport.responseText.evalJSON(true);
28
+ alert(response.description);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ };
34
+
35
+ document.observe("dom:loaded", function() {
36
+ $(shopgo.skynetShipping.verifyAccountButton.elmClassPrefix + 'username').observe(
37
+ 'change', function(event) {
38
+ shopgo.skynetShipping.verifyAccountButton.usernameChanged = 1;
39
+ }
40
+ );
41
+ $(shopgo.skynetShipping.verifyAccountButton.elmClassPrefix + 'password').observe(
42
+ 'change', function(event) {
43
+ shopgo.skynetShipping.verifyAccountButton.passwordChanged = 1;
44
+ }
45
+ );
46
+ });
47
+ //]]></script>
app/etc/modules/Shopgo_SkynetShipping.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shopgo_SkynetShipping>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Shopgo_ShippingCore/>
9
+ </depends>
10
+ </Shopgo_SkynetShipping>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Shopgo_SkynetShipping</name>
4
+ <version>1.0.7</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>SkyNet Worldwide Express allows to do SkyNet rate calculation and shipment creation easily inside Magento.</summary>
10
+ <description>&lt;p&gt;SkyNet Worldwide Express is a shipping module that allows customers to do SkyNet rate calculation and shipment creation easily inside Magento website.&lt;/p&gt;&#xD;
11
+ &lt;p&gt;Full tracking, shipping labels printing and pickups creation features will be added in future releases.&lt;/p&gt;&#xD;
12
+ You could also get the latest version of the module from:&#xD;
13
+ &lt;a href="https://github.com/shopgo-me/skynet-shipping.git"&gt;https://github.com/shopgo-me/skynet-shipping.git&lt;/a&gt;</description>
14
+ <notes>The first release of SkyNet Worldwide Express module.</notes>
15
+ <authors><author><name>ShopGo</name><user>ShopGo</user><email>support@shopgo.me</email></author></authors>
16
+ <date>2015-07-10</date>
17
+ <time>01:18:25</time>
18
+ <contents><target name="magecommunity"><dir name="Shopgo"><dir name="SkynetShipping"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Shipment"><dir name="Create"><dir name="Form"><file name="Abstract.php" hash="e8799fc3361537948eacce935043bf14"/><file name="Shipment.php" hash="fb84f878fde877056864f5280644a216"/></dir></dir></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="ServiceListButton.php" hash="e5d0702c85016561e3ea4af38ba5f9fb"/><file name="VerifyAccountButton.php" hash="d7c07c1fe8d3eb96c76bd9d1c531cd8f"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="3d35a227b6bfeecc86dee03f756f7f58"/></dir><dir name="Model"><dir name="Carrier"><file name="Skynet.php" hash="ebf2f358f8170d3d174f6119fdc107c1"/></dir><dir name="Resource"><dir name="Service"><file name="Collection.php" hash="b63e98f9171aaa09de46e08746803e9a"/></dir><file name="Service.php" hash="6c91083cfefc36f51fa3feb7d3675fd7"/></dir><file name="Service.php" hash="985ca70df79471992e0c499266cb87ff"/><dir name="Shipment"><dir name="Source"><file name="Typeofshipment.php" hash="b8f58fb33bf79a2ad833dec1e639948d"/></dir></dir><file name="Shipment.php" hash="5efa6ba625929e22b7ad4f3895b47858"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Service.php" hash="834d5888d87ad38bb1146b3667890d58"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="SkynetController.php" hash="023b507ba379f2e0bb33b517912e95fb"/></dir></dir><dir name="etc"><file name="config.xml" hash="c16a16aa20e900820e53609630eb7a3d"/><file name="system.xml" hash="7d84ba307e0f958a0c769934aa233d6a"/></dir><dir name="sql"><dir name="skynetshipping_setup"><file name="mysql4-install-1.0.0.php" hash="e5ade6d196777a4b32a23ed998baebbc"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="shopgo"><file name="skynet_shipping.xml" hash="c871e625bfb49e1bd35a1d4f3e9d3de4"/></dir></dir><dir name="template"><dir name="shopgo"><dir name="skynet_shipping"><dir name="sales"><dir name="order"><dir name="shipment"><dir name="create"><dir name="form"><file name="shipment.phtml" hash="9d6ab95235328cde24787cfd2994e8a8"/></dir></dir></dir></dir></dir><dir name="system"><dir name="config"><file name="service_list_button.phtml" hash="e9833dbe433f5eef9387a07d1764c6b7"/><file name="verify_account_button.phtml" hash="6bad73f6bbfac741f80be7bde6b252cd"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shopgo_SkynetShipping.xml" hash="4f43294a53ee8ea3d0e825b7c93ce5d2"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="shopgo"><dir name="skynet_shipping"><dir name="sales"><dir name="order"><dir name="shipment"><dir name="create"><dir name="form"><dir name="css"><file name="main.css" hash="6df04f2008a3fe635c9d40a2bbde272b"/><file name="shipment.css" hash="ee66afde21b13a8d8b7c89c17573a4a1"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
19
+ <compatible/>
20
+ <dependencies><required><php><min>5.3.0</min><max>7.0.0</max></php><package><name>Shopgo_Core</name><channel>community</channel><min>1.0.6</min><max/></package><package><name>Shopgo_ShippingCore</name><channel>community</channel><min>1.3.7</min><max/></package><package><name>Shopgo_AdvIfconfig</name><channel>community</channel><min>1.0.3</min><max/></package><package><name>Phoenix_CashOnDelivery</name><channel>community</channel><min>1.0.8</min><max/></package></required></dependencies>
21
+ </package>
skin/adminhtml/default/default/shopgo/skynet_shipping/sales/order/shipment/create/form/css/main.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ .shopgo-skynet-container-table table td {
2
+ padding: 7px 0;
3
+ }
4
+
5
+ .shopgo-skynet-container-table .field.table table td {
6
+ padding: 0;
7
+ }
skin/adminhtml/default/default/shopgo/skynet_shipping/sales/order/shipment/create/form/css/shipment.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #shopgo_skynet_shipment_container .fieldset.shipment-details table td.label {
2
+ width: 175px;
3
+ }
4
+
5
+ #shopgo_skynet_shipment_container .fieldset.shipment-details table td.field input[type="text"] {
6
+ width: 150px;
7
+ }
8
+
9
+ #shopgo_skynet_shipment_container .fieldset.shipment-details table td.field select {
10
+ padding: 0 30px 0 0;
11
+ }