Overview

Packages

  • IllApps
    • Shipsync
  • PHP

Classes

  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Abstract
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Form
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Items
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Package
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_View
  • IllApps_Shipsync_Block_Adminhtml_Shipsync
  • IllApps_Shipsync_Block_Adminhtml_Shipsync_Option
  • IllApps_Shipsync_Helper_Data
  • IllApps_Shipsync_IndexController
  • IllApps_Shipsync_Model_Mysql4_Setup
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package_Collection
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package_Item
  • IllApps_Shipsync_Model_Sales_Quote_Address
  • IllApps_Shipsync_Model_Shipment_Abstract
  • IllApps_Shipsync_Model_Shipment_Package
  • IllApps_Shipsync_Model_Shipment_Request
  • IllApps_Shipsync_Model_Shipment_Response
  • IllApps_Shipsync_Model_Shipment_Result
  • IllApps_Shipsync_Model_Shipping_Carrier_Abstract
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Address
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Package
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Ship
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_B13afilingoption
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Freemethod
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Image
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Orientation
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Stock
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Method
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Packaging
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Ratediscount
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Residencedelivery
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Signature
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Endorsement
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Indicia
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Unitofmeasure
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Track
  • IllApps_Shipsync_Model_Shipping_Package
  • IllApps_Shipsync_Model_Shipping_Package_Item
  • IllApps_Shipsync_Model_Shipping_Package_Origins
  • IllApps_Shipsync_Model_Shipping_Package_Sort
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * ShipSync
  5:  *
  6:  * @category   IllApps
  7:  * @package    IllApps_Shipsync
  8:  * @copyright  Copyright (c) 2014 EcoMATICS, Inc. DBA IllApps (http://www.illapps.com)
  9:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 10:  */
 11: 
 12: /**
 13:  * IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Track
 14:  */
 15: class IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Track extends IllApps_Shipsync_Model_Shipping_Carrier_Fedex
 16: {
 17: 
 18: 
 19:     protected $_trackRequest;
 20:     protected $_trackResult;
 21:     protected $_trackResultError;
 22:     protected $_trackServiceClient;
 23:     protected $_trackServiceVersion = '5';
 24:     protected $_trackServiceWsdlPath = 'TrackService_v5.wsdl';
 25: 
 26: 
 27: 
 28:     /**
 29:      * getTracking
 30:      *
 31:      * @param array $trackings
 32:      * @return mixed
 33:      */
 34:     public function getTracking($trackings)
 35:     {
 36:         // Track service client
 37:     $this->_trackServiceClient = $this->_initWebServices($this->_trackServiceWsdlPath);
 38: 
 39:         // Set the request
 40:     $this->setTrackingRequest();
 41: 
 42:         if (!is_array($trackings)) { $_trackings = array($trackings); }
 43:         else                       { $_trackings = $trackings; }
 44:         
 45:         foreach ($_trackings as $_tracking) { $this->_getWsdlTracking($_tracking); }                        
 46:                 
 47:         return $this->_trackResult;
 48:     }
 49: 
 50: 
 51: 
 52:     /**
 53:      * setTrackingRequest
 54:      */
 55:     protected function setTrackingRequest()
 56:     {           
 57:     $this->_trackRequest = new Varien_Object();
 58:     }
 59: 
 60:             
 61:         
 62:         
 63:     /**
 64:      * _getWsdlTracking
 65:      * 
 66:      * @param string $tracking
 67:      */
 68:     protected function _getWsdlTracking($tracking)
 69:     {
 70:         $trackRequest        = $this->_trackRequest;
 71:     $trackServiceVersion = $this->_trackServiceVersion;
 72:     
 73:     $request['WebAuthenticationDetail'] = array(
 74:         'UserCredential' => array(
 75:         'Key'      => $this->getFedexKey(),
 76:         'Password' => $this->getFedexPassword()));
 77: 
 78:     $request['ClientDetail'] = array(
 79:         'AccountNumber' => $this->getFedexAccount(),
 80:         'MeterNumber'   => $this->getFedexMeter());
 81: 
 82:     $request['TransactionDetail']['CustomerTransactionId'] = '*** Track Request v' . $trackServiceVersion . ' Using PHP ***';
 83: 
 84:     $request['Version'] = array('ServiceId' => 'trck', 'Major' => $trackServiceVersion, 'Intermediate' => '0', 'Minor' => '0');
 85: 
 86:         $request['PackageIdentifier']['Value'] = $tracking;
 87:     $request['PackageIdentifier']['Type']  = 'TRACKING_NUMBER_OR_DOORTAG';
 88:         $request['IncludeDetailedScans'] = true;
 89: 
 90:         try
 91:         {
 92:             Mage::Helper('shipsync')->mageLog($request, 'track');
 93:             $response = $this->_trackServiceClient->track($request);
 94:             Mage::Helper('shipsync')->mageLog($response, 'track');
 95: 
 96: 
 97:             $this->_parseWsdlTrackingResponse($tracking, $response);
 98:         }
 99:         catch (SoapFault $ex)
100:         {
101:             $this->_trackResultError = $ex->getMessage();
102:         }
103:     }
104: 
105: 
106: 
107:     /**
108:      * _parseWsdlTrackingResponse
109:      * 
110:      * @param string $tracking
111:      * @param object $response
112:      * @return array
113:      */
114:     protected function _parseWsdlTrackingResponse($tracking, $response)
115:     {
116:         if (!$this->_trackResult)
117:         {
118:             $this->_trackResult = Mage::getModel('shipping/tracking_result');
119:         }
120:         
121:         if ($response->HighestSeverity == 'FAILURE' || $response->HighestSeverity == 'ERROR')
122:         {
123:             $errorMsg = '';
124:             
125:         if (is_array($response->Notifications)) {
126:                 foreach ($response->Notifications as $notification) {
127:             $errorMsg .= $notification->Severity . ': ' .  $notification->Message . '<br />';
128:         }
129:         }
130:         else { $errorMsg .= $response->Notifications->Severity . ': ' . $response->Notifications->Message . '<br />'; }
131: 
132:         $error = Mage::getModel('shipping/tracking_result_error');
133:             $error->setCarrier('fedex');
134:             $error->setCarrierTitle(Mage::getStoreConfig('carriers/fedex/title'));
135:             $error->setTracking($tracking);
136:             $error->setErrorMessage($errorMsg);
137: 
138:             $this->_trackResult->append($error);
139:     }
140:         else
141:         {
142:             if (!is_array($response->TrackDetails)) 
143:                  { $trackDetails = array($response->TrackDetails); }
144:             else { $trackDetails = $response->TrackDetails; }
145: 
146:             foreach ($trackDetails as $trackDetail)
147:             {
148:                 $trackResultArray = array();
149: 
150:                 $trackResultArray['service'] = isset($trackDetail->ServiceInfo) ? $trackDetail->ServiceInfo : '';
151:                 $trackResultArray['status']  = $trackDetail->StatusDescription;
152: 
153:                 if (isset($trackDetail->EstimatedDeliveryTimestamp))
154:                 {
155:                     $timestamp = explode('T', $trackDetail->EstimatedDeliveryTimestamp);
156: 
157:                     $trackResultArray['deliverydate'] = $timestamp[0];
158:                     $trackResultArray['deliverytime'] = $timestamp[1];
159:                 }                                
160: 
161:                 if (isset($trackDetail->PackageWeight))                   
162:                 {
163:                     $weight = $trackDetail->PackageWeight->Value;
164:                     $unit   = $trackDetail->PackageWeight->Units;
165: 
166:                     $trackResultArray['weight'] = "{$weight} {$unit}";
167:                 }
168: 
169:                 $packageProgress = array();
170: 
171:                 if (isset($trackDetail->Events))                    
172:                 {
173:                     if (!is_array($trackDetail->Events))
174:                          { $events = array($trackDetail->Events); }
175:                     else { $events = $trackDetail->Events; }
176: 
177:                     foreach ($events as $event)
178:                     {
179:                          $detailArray = array();
180: 
181:                          $detailArray['activity'] = $event->EventDescription;
182: 
183:                          $timestamp = explode('T', $event->Timestamp);
184: 
185:                          $detailArray['deliverydate'] = $timestamp[0];
186:                          $detailArray['deliverytime'] = $timestamp[1];                    
187: 
188:                          $addressArray = array();
189: 
190:                           if (isset($event->Address->City)) {
191:                             $addressArray[] = (string)$event->Address->City;
192:                           }
193:                           if (isset($event->Address->StateProvinceCode)) {
194:                             $addressArray[] = (string)$event->Address->StateProvinceCode;
195:                           }
196:                           if (isset($event->Address->CountryCode)) {
197:                             $addressArray[] = (string)$event->Address->CountryCode;
198:                           }
199:                           if ($addressArray) {
200:                             $detailArray['deliverylocation'] = implode(', ', $addressArray);
201:                           }
202:                           
203:                           $packageProgress[] = $detailArray;                                                  
204:                     }                                              
205: 
206:                     $trackResultArray['progressdetail'] = $packageProgress;                
207:                 }             
208:                 
209:                 if ($trackResultArray)
210:                 {
211:                     $trackResultStatus = Mage::getModel('shipping/tracking_result_status');
212:                     $trackResultStatus->setCarrier('fedex');
213:                     $trackResultStatus->setCarrierTitle(Mage::getStoreConfig('carriers/fedex/title'));
214:                     $trackResultStatus->setTracking($tracking);
215:                     $trackResultStatus->addData($trackResultArray);
216: 
217:                     $this->_trackResult->append($trackResultStatus);
218:                 }
219:                 else
220:                 {
221:                     $error = Mage::getModel('shipping/tracking_result_error');
222:                     $error->setCarrier('fedex');
223:                     $error->setCarrierTitle(Mage::getStoreConfig('carriers/fedex/title'));
224:                     $error->setTracking($tracking);
225:                     $error->setErrorMessage('No tracking results retrieved.  Please try again later.');
226: 
227:                     $this->_trackResult->append($error);
228:                 }
229:             }                
230:         }
231:     }
232:     
233: }
234: 
shipsync-community API documentation generated by ApiGen 2.8.0