Mage_Usa_Model_Shipping_Carrier_Fedex Class Reference

Inheritance diagram for Mage_Usa_Model_Shipping_Carrier_Fedex:

Mage_Usa_Model_Shipping_Carrier_Abstract Mage_Shipping_Model_Carrier_Interface Mage_Shipping_Model_Carrier_Abstract Varien_Object

List of all members.

Public Member Functions

 collectRates (Mage_Shipping_Model_Rate_Request $request)
 setRequest (Mage_Shipping_Model_Rate_Request $request)
 getResult ()
 getCode ($type, $code='')
 getCurrencyCode ()
 getTracking ($trackings)
 getResponse ()
 getAllowedMethods ()

Protected Member Functions

 _getQuotes ()
 _setFreeMethodRequest ($freeMethod)
 _getXmlQuotes ()
 _parseXmlResponse ($response)
 setTrackingReqeust ()
 _getXMLTracking ($tracking)
 _parseXmlTrackingResponse ($trackingvalue, $response)

Protected Attributes

 $_code = 'fedex'
 $_request = null
 $_result = null
 $_gatewayUrl = 'https://gateway.fedex.com/GatewayDC'


Detailed Description

Definition at line 34 of file Fedex.php.


Member Function Documentation

_getQuotes (  )  [protected]

Definition at line 138 of file Fedex.php.

00139     {
00140         return $this->_getXmlQuotes();
00141     }

_getXmlQuotes (  )  [protected]

FDXE � FedEx Express FDXG � FedEx Ground

� NONRETURN � PRINTRETURNLABEL � EMAILLABEL

� REGULARPICKUP � REQUESTCOURIER � DROPBOX � BUSINESSSERVICECENTER � STATION Only REGULARPICKUP, REQUESTCOURIER, and STATION are allowed with international freight shipping.

One of the following FedEx Services is optional: � PRIORITYOVERNIGHT � STANDARDOVERNIGHT � FIRSTOVERNIGHT � FEDEX2DAY � FEDEXEXPRESSSAVER � INTERNATIONALPRIORITY � INTERNATIONALECONOMY � INTERNATIONALFIRST � FEDEX1DAYFREIGHT � FEDEX2DAYFREIGHT � FEDEX3DAYFREIGHT � FEDEXGROUND � GROUNDHOMEDELIVERY � INTERNATIONALPRIORITY FREIGHT � INTERNATIONALECONOMY FREIGHT � EUROPEFIRSTINTERNATIONALPRIORITY If provided, only that service�s estimated charges will be returned.

One of the following package types is required: � FEDEXENVELOPE � FEDEXPAK � FEDEXBOX � FEDEXTUBE � FEDEX10KGBOX � FEDEX25KGBOX � YOURPACKAGING If value entered is FEDEXENVELOPE, FEDEX10KGBOX, or FEDEX25KGBOX, an MPS rate quote is not allowed.

� LBS � KGS LBS is required for a U.S. FedEx Express rate quote.

Optional. If = true or 1, list-rate courtesy quotes should be returned in addition to the discounted quote.

Optional. Defaults to SENDER. If value other than SENDER is used, no rates will still be returned.

DIMENSIONS

Dimensions / Length Optional. Only applicable if the package type is YOURPACKAGING. The length of a package. Format: Numeric, whole number

Dimensions / Width Optional. Only applicable if the package type is YOURPACKAGING. The width of a package. Format: Numeric, whole number

Dimensions / Height Optional. Only applicable if the package type is YOURPACKAGING. The height of a package. Format: Numeric, whole number

Dimensions / Units Required if dimensions are entered. Only applicable if the package type is YOURPACKAGING. The valid unit of measure codes for the package dimensions are: IN � Inches CM � Centimeters U.S. FedEx Express must be in inches.

Valid values: ACCESSIBLE � accessible DG INACCESSIBLE � inaccessible DG

If = true or 1, the shipment is Residential Delivery. If Recipient Address is in a rural area (defined by table lookup), additional charge will be applied. This element is not applicable to the FedEx Home Delivery service.

Optional. Specifies the Delivery Signature Option requested for the shipment. Valid values: � DELIVERWITHOUTSIGNATURE � INDIRECT � DIRECT � ADULT For FedEx Express shipments, the DELIVERWITHOUTSIGNATURE option will not be allowed when the following special services are requested: � Alcohol � Hold at Location � Dangerous Goods � Declared Value greater than $500

HOMEDELIVERY

HomeDelivery / Type One of the following values are required for FedEx Home Delivery shipments: � DATECERTAIN � EVENING � APPOINTMENT

PackageCount Required for multiple-piece shipments (MPS). For MPS shipments, 1 piece = 1 box. For international Freight MPS shipments, this is the total number of "units." Units are the skids, pallets, or boxes that make up a freight shipment. Each unit within a shipment should have its own label. FDXE only applies to COD, MPS, and international. Valid values: 1 to 999

VARIABLEHANDLINGCHARGES

VariableHandlingCharges / Level Optional. Only applicable if valid Variable Handling Type is present. Apply fixed or variable handling charges at package or shipment level. Valid values: � PACKAGE � SHIPMENT The value "SHIPMENT" is applicable only on last piece of FedEx Ground or FedEx Express MPS shipment only. Note: Value "SHIPMENT" = shipment level affects the entire shipment. Anything else sent in Child will be ignored.

VariableHandlingCharges / Type Optional. If valid value is present, a valid Variable Handling Charge is required. Specifies what type of Variable Handling charges to assess and on which amount. Valid values: � FIXED_AMOUNT � PERCENTAGE_OF_BASE � PERCENTAGE_OF_NET � PERCENTAGE_OF_NET_ EXCL_TAXES

VariableHandlingCharges / AmountOrPercentage Optional. Required in conjunction with Variable Handling Type. Contains the dollar or percentage amount to be added to the Freight charges. Whether the amount is a dollar or percentage is based on the Variable Handling Type value that is included in this Request. Format: Two explicit decimal positions (e.g. 1.00); 10 total length including decimal place.

Definition at line 151 of file Fedex.php.

00152     {
00153         $r = $this->_rawRequest;
00154         $xml = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><FDXRateAvailableServicesRequest/>');
00155 
00156         $xml->addAttribute('xmlns:api', 'http://www.fedex.com/fsmapi');
00157         $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
00158         $xml->addAttribute('xsi:noNamespaceSchemaLocation', 'FDXRateAvailableServicesRequest.xsd');
00159 
00160         $requestHeader = $xml->addChild('RequestHeader');
00161 //          $requestHeader->addChild('CustomerTransactionIdentifier', 'CTIString');
00162             $requestHeader->addChild('AccountNumber', $r->getAccount());
00163 //          $requestHeader->addChild('MeterNumber', '2436351');  -- my own meter number
00164             $requestHeader->addChild('MeterNumber', '0');
00165 //          $requestHeader->addChild('CarrierCode', 'FDXE');
00166 //          $requestHeader->addChild('CarrierCode', 'FDXG');
00167             /**
00168              *  FDXE � FedEx Express
00169              *  FDXG � FedEx Ground
00170              */
00171 
00172         $xml->addChild('ShipDate', date('Y-m-d'));
00173 //      $xml->addChild('ReturnShipmentIndicator', 'NONRETURN');
00174         /**
00175          *  � NONRETURN
00176          *  � PRINTRETURNLABEL
00177          *  � EMAILLABEL
00178          */
00179         $xml->addChild('DropoffType', $r->getDropoffType());
00180         /**
00181          *  � REGULARPICKUP
00182          *  � REQUESTCOURIER
00183          *  � DROPBOX
00184          *  � BUSINESSSERVICECENTER
00185          *  � STATION
00186          *  Only REGULARPICKUP, REQUESTCOURIER, and STATION are
00187          *  allowed with international freight shipping.
00188          */
00189         if ($r->hasService()) {
00190             $xml->addChild('Service', $r->getService());
00191         }
00192         /**
00193          *  One of the following FedEx Services is optional:
00194          *  � PRIORITYOVERNIGHT
00195          *  � STANDARDOVERNIGHT
00196          *  � FIRSTOVERNIGHT
00197          *  � FEDEX2DAY
00198          *  � FEDEXEXPRESSSAVER
00199          *  � INTERNATIONALPRIORITY
00200          *  � INTERNATIONALECONOMY
00201          *  � INTERNATIONALFIRST
00202          *  � FEDEX1DAYFREIGHT
00203          *  � FEDEX2DAYFREIGHT
00204          *  � FEDEX3DAYFREIGHT
00205          *  � FEDEXGROUND
00206          *  � GROUNDHOMEDELIVERY
00207          *  � INTERNATIONALPRIORITY FREIGHT
00208          *  � INTERNATIONALECONOMY FREIGHT
00209          *  � EUROPEFIRSTINTERNATIONALPRIORITY
00210          *  If provided, only that service�s estimated charges will be returned.
00211          */
00212         $xml->addChild('Packaging', $r->getPackaging());
00213         /**
00214          *  One of the following package types is required:
00215          *  � FEDEXENVELOPE
00216          *  � FEDEXPAK
00217          *  � FEDEXBOX
00218          *  � FEDEXTUBE
00219          *  � FEDEX10KGBOX
00220          *  � FEDEX25KGBOX
00221          *  � YOURPACKAGING
00222          *  If value entered is FEDEXENVELOPE, FEDEX10KGBOX, or
00223          *  FEDEX25KGBOX, an MPS rate quote is not allowed.
00224          */
00225         $xml->addChild('WeightUnits', 'LBS');
00226         /**
00227          *  � LBS
00228          *  � KGS
00229          *  LBS is required for a U.S. FedEx Express rate quote.
00230          */
00231         $xml->addChild('Weight', $r->getWeight());
00232 //      $xml->addChild('ListRate', 'true');
00233         /**
00234          *  Optional.
00235          *  If = true or 1, list-rate courtesy quotes should be returned in addition to
00236          *  the discounted quote.
00237          */
00238 
00239         $originAddress = $xml->addChild('OriginAddress');
00240 //          $originAddress->addChild('StateOrProvinceCode', 'GA');   -- ???
00241             $originAddress->addChild('PostalCode', $r->getOrigPostal());
00242             $originAddress->addChild('CountryCode', $r->getOrigCountry());
00243 
00244         $destinationAddress = $xml->addChild('DestinationAddress');
00245 //          $destinationAddress->addChild('StateOrProvinceCode', 'GA');   -- ???
00246             $destinationAddress->addChild('PostalCode', $r->getDestPostal());
00247             $destinationAddress->addChild('CountryCode', $r->getDestCountry());
00248 
00249         $payment = $xml->addChild('Payment');
00250             $payment->addChild('PayorType', 'SENDER');
00251             /**
00252              *  Optional.
00253              *  Defaults to SENDER.
00254              *  If value other than SENDER is used, no rates will still be returned.
00255              */
00256 
00257         /**
00258          *  DIMENSIONS
00259          *
00260          *  Dimensions / Length
00261          *  Optional.
00262          *  Only applicable if the package type is YOURPACKAGING.
00263          *  The length of a package.
00264          *  Format: Numeric, whole number
00265          *
00266          *  Dimensions / Width
00267          *  Optional.
00268          *  Only applicable if the package type is YOURPACKAGING.
00269          *  The width of a package.
00270          *  Format: Numeric, whole number
00271          *
00272          *  Dimensions / Height
00273          *  Optional.
00274          *  Only applicable if the package type is YOURPACKAGING.
00275          *  The height of a package.
00276          *  Format: Numeric, whole number
00277          *
00278          *  Dimensions / Units
00279          *  Required if dimensions are entered.
00280          *  Only applicable if the package type is YOURPACKAGING.
00281          *  The valid unit of measure codes for the package dimensions are:
00282          *  IN � Inches
00283          *  CM � Centimeters
00284          *  U.S. FedEx Express must be in inches.
00285          */
00286 
00287         $declaredValue = $xml->addChild('DeclaredValue');
00288             $declaredValue->addChild('Value', $r->getValue());
00289 //            $declaredValue->addChild('CurrencyCode', 'USD');
00290             $declaredValue->addChild('CurrencyCode', $this->getCurrencyCode());
00291 
00292         if ($this->getConfigData('residence_delivery')) {
00293             $specialServices = $xml->addChild('SpecialServices');
00294                  $specialServices->addChild('ResidentialDelivery', 'true');
00295         }
00296 
00297 //      $specialServices = $xml->addChild('SpecialServices');
00298 //          $specialServices->addChild('Alcohol', 'true');
00299 //          $specialServices->addChild('DangerousGoods', 'true')->addChild('Accessibility', 'ACCESSIBLE');
00300         /**
00301          *  Valid values:
00302          *  ACCESSIBLE � accessible DG
00303          *  INACCESSIBLE � inaccessible DG
00304          */
00305 //          $specialServices->addChild('DryIce', 'true');
00306 //          $specialServices->addChild('ResidentialDelivery', 'true');
00307         /**
00308          *  If = true or 1, the shipment is Residential Delivery. If Recipient Address
00309          *  is in a rural area (defined by table lookup), additional charge will be
00310          *  applied. This element is not applicable to the FedEx Home Delivery
00311          *  service.
00312          */
00313 //          $specialServices->addChild('InsidePickup', 'true');
00314 //          $specialServices->addChild('InsideDelivery', 'true');
00315 //          $specialServices->addChild('SaturdayPickup', 'true');
00316 //          $specialServices->addChild('SaturdayDelivery', 'true');
00317 //          $specialServices->addChild('NonstandardContainer', 'true');
00318 //          $specialServices->addChild('SignatureOption', 'true');
00319         /**
00320          *  Optional.
00321          *  Specifies the Delivery Signature Option requested for the shipment.
00322          *  Valid values:
00323          *  � DELIVERWITHOUTSIGNATURE
00324          *  � INDIRECT
00325          *  � DIRECT
00326          *  � ADULT
00327          *  For FedEx Express shipments, the DELIVERWITHOUTSIGNATURE
00328          *  option will not be allowed when the following special services are
00329          *  requested:
00330          *  � Alcohol
00331          *  � Hold at Location
00332          *  � Dangerous Goods
00333          *  � Declared Value greater than $500
00334          */
00335 
00336         /**
00337          *  HOMEDELIVERY
00338          *
00339          *  HomeDelivery / Type
00340          *  One of the following values are required for FedEx Home Delivery
00341          *  shipments:
00342          *  � DATECERTAIN
00343          *  � EVENING
00344          *  � APPOINTMENT
00345          *
00346          *  PackageCount
00347          *  Required for multiple-piece shipments (MPS).
00348          *  For MPS shipments, 1 piece = 1 box.
00349          *  For international Freight MPS shipments, this is the total number of
00350          *  "units." Units are the skids, pallets, or boxes that make up a freight
00351          *  shipment.
00352          *  Each unit within a shipment should have its own label.
00353          *  FDXE only applies to COD, MPS, and international.
00354          *  Valid values: 1 to 999
00355          */
00356 
00357         /**
00358          *  VARIABLEHANDLINGCHARGES
00359          *
00360          *  VariableHandlingCharges / Level
00361          *  Optional.
00362          *  Only applicable if valid Variable Handling Type is present.
00363          *  Apply fixed or variable handling charges at package or shipment level.
00364          *  Valid values:
00365          *  � PACKAGE
00366          *  � SHIPMENT
00367          *  The value "SHIPMENT" is applicable only on last piece of FedEx
00368          *  Ground or FedEx Express MPS shipment only.
00369          *  Note: Value "SHIPMENT" = shipment level affects the entire shipment.
00370          *  Anything else sent in Child will be ignored.
00371          *
00372          *  VariableHandlingCharges / Type
00373          *  Optional.
00374          *  If valid value is present, a valid Variable Handling Charge is required.
00375          *  Specifies what type of Variable Handling charges to assess and on
00376          *  which amount.
00377          *  Valid values:
00378          *  � FIXED_AMOUNT
00379          *  � PERCENTAGE_OF_BASE
00380          *  � PERCENTAGE_OF_NET
00381          *  � PERCENTAGE_OF_NET_ EXCL_TAXES
00382          *
00383          *  VariableHandlingCharges / AmountOrPercentage
00384          *  Optional.
00385          *  Required in conjunction with Variable Handling Type.
00386          *  Contains the dollar or percentage amount to be added to the Freight
00387          *  charges. Whether the amount is a dollar or percentage is based on the
00388          *  Variable Handling Type value that is included in this Request.
00389          *  Format: Two explicit decimal positions (e.g. 1.00); 10 total length
00390          *  including decimal place.
00391          */
00392 
00393         $xml->addChild('PackageCount', '1');
00394 
00395         $request = $xml->asXML();
00396 /*
00397         $client = new Zend_Http_Client();
00398         $client->setUri($this->getConfigData('gateway_url'));
00399         $client->setConfig(array('maxredirects'=>0, 'timeout'=>30));
00400         $client->setParameterPost($request);
00401         $response = $client->request();
00402         $responseBody = $response->getBody();
00403 */
00404 
00405         try {
00406             $url = $this->getConfigData('gateway_url');
00407             if (!$url) {
00408                 $url = $this->_defaultGatewayUrl;
00409             }
00410             $ch = curl_init();
00411             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
00412             curl_setopt($ch, CURLOPT_URL, $url);
00413             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
00414             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
00415             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
00416             $responseBody = curl_exec($ch);
00417             curl_close ($ch);
00418         } catch (Exception $e) {
00419             $responseBody = '';
00420         }
00421 
00422         return $this->_parseXmlResponse($responseBody);
00423     }

_getXMLTracking ( tracking  )  [protected]

Definition at line 598 of file Fedex.php.

00599     {
00600         $r = $this->_rawTrackingRequest;
00601 
00602         $xml = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><FDXTrack2Request/>');
00603         $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
00604         $xml->addAttribute('xsi:noNamespaceSchemaLocation', 'FDXTrack2Request.xsd');
00605 
00606         $requestHeader = $xml->addChild('RequestHeader');
00607         $requestHeader->addChild('AccountNumber', $r->getAccount());
00608 
00609         /*
00610         * for tracking result, actual meter number is not needed
00611         */
00612         $requestHeader->addChild('MeterNumber', '0');
00613 
00614         $packageIdentifier = $xml->addChild('PackageIdentifier');
00615         $packageIdentifier->addChild('Value', $tracking);
00616 
00617         /*
00618         * 0 = summary data, one signle scan structure with the most recent scan
00619         * 1 = multiple sacn activity for each package
00620         */
00621         $xml->addChild('DetailScans', '1');
00622 
00623         $request = $xml->asXML();
00624         try {
00625             $url = $this->getConfigData('gateway_url');
00626             if (!$url) {
00627                 $url = $this->_defaultGatewayUrl;
00628             }
00629             $ch = curl_init();
00630             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
00631             curl_setopt($ch, CURLOPT_URL, $url);
00632             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
00633             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
00634             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
00635             $responseBody = curl_exec($ch);
00636             curl_close ($ch);
00637         } catch (Exception $e) {
00638             $responseBody = '';
00639         }
00640 
00641         #echo "<xmp>".$responseBody."</xmp>";
00642         $this->_parseXmlTrackingResponse($tracking, $responseBody);
00643     }

_parseXmlResponse ( response  )  [protected]

Definition at line 425 of file Fedex.php.

00426     {
00427         $costArr = array();
00428         $priceArr = array();
00429         $errorTitle = 'Unable to retrieve quotes';
00430         if (strlen(trim($response))>0) {
00431             if (strpos(trim($response), '<?xml')===0) {
00432                 $xml = simplexml_load_string($response);
00433                 if (is_object($xml)) {
00434                     if (is_object($xml->Error) && is_object($xml->Error->Message)) {
00435                         $errorTitle = (string)$xml->Error->Message;
00436                     } elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
00437                         $errorTitle = (string)$xml->SoftError->Message;
00438                     } else {
00439                         $errorTitle = 'Unknown error';
00440                     }
00441                     $allowedMethods = explode(",", $this->getConfigData('allowed_methods'));
00442                     foreach ($xml->Entry as $entry) {
00443                         if (in_array((string)$entry->Service, $allowedMethods)) {
00444                             $costArr[(string)$entry->Service] = (string)$entry->EstimatedCharges->DiscountedCharges->NetCharge;
00445                             $priceArr[(string)$entry->Service] = $this->getMethodPrice((string)$entry->EstimatedCharges->DiscountedCharges->NetCharge, (string)$entry->Service);
00446                         }
00447                     }
00448                     asort($priceArr);
00449                 }
00450             } else {
00451                 $errorTitle = 'Response is in the wrong format';
00452             }
00453         }
00454 
00455         $result = Mage::getModel('shipping/rate_result');
00456         $defaults = $this->getDefaults();
00457         if (empty($priceArr)) {
00458             $error = Mage::getModel('shipping/rate_result_error');
00459             $error->setCarrier('fedex');
00460             $error->setCarrierTitle($this->getConfigData('title'));
00461             //$error->setErrorMessage($errorTitle);
00462             $error->setErrorMessage($this->getConfigData('specificerrmsg'));
00463             $result->append($error);
00464         } else {
00465             foreach ($priceArr as $method=>$price) {
00466                 $rate = Mage::getModel('shipping/rate_result_method');
00467                 $rate->setCarrier('fedex');
00468                 $rate->setCarrierTitle($this->getConfigData('title'));
00469                 $rate->setMethod($method);
00470                 $rate->setMethodTitle($this->getCode('method', $method));
00471                 $rate->setCost($costArr[$method]);
00472                 $rate->setPrice($price);
00473                 $result->append($rate);
00474             }
00475         }
00476         return $result;
00477     }

_parseXmlTrackingResponse ( trackingvalue,
response 
) [protected]

Definition at line 645 of file Fedex.php.

00646     {
00647          $resultArr=array();
00648          if (strlen(trim($response))>0) {
00649               if (strpos(trim($response), '<?xml')===0) {
00650                   $xml = simplexml_load_string($response);
00651                   if (is_object($xml)) {
00652                     if (is_object($xml->Error) && is_object($xml->Error->Message)) {
00653                         $errorTitle = (string)$xml->Error->Message;
00654                     } elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
00655                         $errorTitle = (string)$xml->SoftError->Message;
00656                     }
00657                   }else{
00658                       $errorTitle = 'Error in loading response';
00659                   }
00660 
00661                   if (!isset($errorTitle)) {
00662                       $resultArr['status'] = (string)$xml->Package->StatusDescription;
00663                       $resultArr['service'] = (string)$xml->Package->Service;
00664                       $resultArr['deliverydate'] = (string)$xml->Package->DeliveredDate;
00665                       $resultArr['deliverytime'] = (string)$xml->Package->DeliveredTime;
00666                       $resultArr['deliverylocation'] = (string)$xml->TrackProfile->DeliveredLocationDescription;
00667                       $resultArr['signedby'] = (string)$xml->Package->SignedForBy;
00668                       $resultArr['shippeddate'] = (string)$xml->Package->ShipDate;
00669                       $weight = (string)$xml->Package->Weight;
00670                       $unit = (string)$xml->Package->WeightUnits;
00671                       $resultArr['weight'] = "{$weight} {$unit}";
00672 
00673                       $packageProgress = array();
00674                       if (isset($xml->Package->Event)) {
00675                           foreach ($xml->Package->Event as $event) {
00676                               $tempArr=array();
00677                               $tempArr['activity'] = (string)$event->Description;
00678                               $tempArr['deliverydate'] = (string)$event->Date;//YYYY-MM-DD
00679                               $tempArr['deliverytime'] = (string)$event->Time;//HH:MM:ss
00680                               $addArr=array();
00681                               if (isset($event->Address->City)) {
00682                                 $addArr[] = (string)$event->Address->City;
00683                               }
00684                               if (isset($event->Address->StateProvinceCode)) {
00685                                 $addArr[] = (string)$event->Address->StateProvinceCode;
00686                               }
00687                               if (isset($event->Address->CountryCode)) {
00688                                 $addArr[] = (string)$event->Address->CountryCode;
00689                               }
00690                               if ($addArr) {
00691                                 $tempArr['deliverylocation']=implode(', ',$addArr);
00692                               }
00693                               $packageProgress[] = $tempArr;
00694                           }
00695                       }
00696 
00697                       $resultArr['progressdetail'] = $packageProgress;
00698                 }
00699               } else {
00700                 $errorTitle = 'Response is in the wrong format';
00701               }
00702          } else {
00703              $errorTitle = false;
00704          }
00705 
00706          if(!$this->_result){
00707              $this->_result = Mage::getModel('shipping/tracking_result');
00708          }
00709          $defaults = $this->getDefaults();
00710 
00711          if($resultArr){
00712              $tracking = Mage::getModel('shipping/tracking_result_status');
00713              $tracking->setCarrier('fedex');
00714              $tracking->setCarrierTitle($this->getConfigData('title'));
00715              $tracking->setTracking($trackingvalue);
00716              $tracking->addData($resultArr);
00717              $this->_result->append($tracking);
00718          }else{
00719             $error = Mage::getModel('shipping/tracking_result_error');
00720             $error->setCarrier('fedex');
00721             $error->setCarrierTitle($this->getConfigData('title'));
00722             $error->setTracking($trackingvalue);
00723             $error->setErrorMessage($errorTitle ? $errorTitle : Mage::helper('usa')->__('Unable to retrieve tracking'));
00724             $this->_result->append($error);
00725          }
00726     }

_setFreeMethodRequest ( freeMethod  )  [protected]

Definition at line 143 of file Fedex.php.

00144     {
00145         $r = $this->_rawRequest;
00146         $weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight());
00147         $r->setWeight($weight);
00148         $r->setService($freeMethod);
00149     }

collectRates ( Mage_Shipping_Model_Rate_Request request  ) 

Reimplemented from Mage_Shipping_Model_Carrier_Abstract.

Definition at line 47 of file Fedex.php.

00048     {
00049         if (!$this->getConfigFlag('active')) {
00050             return false;
00051         }
00052 
00053         $this->setRequest($request);
00054 
00055         $this->_result = $this->_getQuotes();
00056 
00057         $this->_updateFreeMethodQuote($request);
00058 
00059         return $this->getResult();
00060     }

getAllowedMethods (  ) 

Get allowed shipping methods

Returns:
array

Implements Mage_Shipping_Model_Carrier_Interface.

Definition at line 755 of file Fedex.php.

00756     {
00757         $allowed = explode(',', $this->getConfigData('allowed_methods'));
00758         $arr = array();
00759         foreach ($allowed as $k) {
00760             $arr[$k] = $this->getCode('method', $k);
00761         }
00762         return $arr;
00763     }

getCode ( type,
code = '' 
)

Definition at line 486 of file Fedex.php.

00487     {
00488         $codes = array(
00489 
00490             'method'=>array(
00491                 'PRIORITYOVERNIGHT'                => Mage::helper('usa')->__('Priority Overnight'),
00492                 'STANDARDOVERNIGHT'                => Mage::helper('usa')->__('Standard Overnight'),
00493                 'FIRSTOVERNIGHT'                   => Mage::helper('usa')->__('First Overnight'),
00494                 'FEDEX2DAY'                        => Mage::helper('usa')->__('2Day'),
00495                 'FEDEXEXPRESSSAVER'                => Mage::helper('usa')->__('Express Saver'),
00496                 'INTERNATIONALPRIORITY'            => Mage::helper('usa')->__('International Priority'),
00497                 'INTERNATIONALECONOMY'             => Mage::helper('usa')->__('International Economy'),
00498                 'INTERNATIONALFIRST'               => Mage::helper('usa')->__('International First'),
00499                 'FEDEX1DAYFREIGHT'                 => Mage::helper('usa')->__('1 Day Freight'),
00500                 'FEDEX2DAYFREIGHT'                 => Mage::helper('usa')->__('2 Day Freight'),
00501                 'FEDEX3DAYFREIGHT'                 => Mage::helper('usa')->__('3 Day Freight'),
00502                 'FEDEXGROUND'                      => Mage::helper('usa')->__('Ground'),
00503                 'GROUNDHOMEDELIVERY'               => Mage::helper('usa')->__('Home Delivery'),
00504                 'INTERNATIONALPRIORITY FREIGHT'    => Mage::helper('usa')->__('Intl Priority Freight'),
00505                 'INTERNATIONALECONOMY FREIGHT'     => Mage::helper('usa')->__('Intl Economy Freight'),
00506                 'EUROPEFIRSTINTERNATIONALPRIORITY' => Mage::helper('usa')->__('Europe First Priority'),
00507             ),
00508 
00509             'dropoff'=>array(
00510                 'REGULARPICKUP'         => Mage::helper('usa')->__('Regular Pickup'),
00511                 'REQUESTCOURIER'        => Mage::helper('usa')->__('Request Courier'),
00512                 'DROPBOX'               => Mage::helper('usa')->__('Drop Box'),
00513                 'BUSINESSSERVICECENTER' => Mage::helper('usa')->__('Business Service Center'),
00514                 'STATION'               => Mage::helper('usa')->__('Station'),
00515             ),
00516 
00517             'packaging'=>array(
00518                 'FEDEXENVELOPE' => Mage::helper('usa')->__('FedEx Envelope'),
00519                 'FEDEXPAK'      => Mage::helper('usa')->__('FedEx Pak'),
00520                 'FEDEXBOX'      => Mage::helper('usa')->__('FedEx Box'),
00521                 'FEDEXTUBE'     => Mage::helper('usa')->__('FedEx Tube'),
00522                 'FEDEX10KGBOX'  => Mage::helper('usa')->__('FedEx 10kg Box'),
00523                 'FEDEX25KGBOX'  => Mage::helper('usa')->__('FedEx 25kg Box'),
00524                 'YOURPACKAGING' => Mage::helper('usa')->__('Your Packaging'),
00525             ),
00526 
00527         );
00528 
00529         if (!isset($codes[$type])) {
00530 //            throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid FedEx XML code type: %s', $type));
00531             return false;
00532         } elseif (''===$code) {
00533             return $codes[$type];
00534         }
00535 
00536         if (!isset($codes[$type][$code])) {
00537 //            throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid FedEx XML code for type %s: %s', $type, $code));
00538             return false;
00539         } else {
00540             return $codes[$type][$code];
00541         }
00542     }

getCurrencyCode (  ) 

Return FeDex currency ISO code by Magento Base Currency Code

Returns:
string 3-digit currency code

Definition at line 549 of file Fedex.php.

00550     {
00551         $codes = array(
00552             'DOP' => 'RDD', // Dominican Peso
00553             'XCD' => 'ECD', // Caribbean Dollars
00554             'ARS' => 'ARN', // Argentina Peso
00555             'SGD' => 'SID', // Singapore Dollars
00556             'KRW' => 'WON', // South Korea Won
00557             'JMD' => 'JAD', // Jamaican Dollars
00558             'CHF' => 'SFR', // Swiss Francs
00559             'JPY' => 'JYE', // Japanese Yen
00560             'KWD' => 'KUD', // Kuwaiti Dinars
00561             'GBP' => 'UKL', // British Pounds
00562             'AED' => 'DHS', // UAE Dirhams
00563             'MXN' => 'NMP', // Mexican Pesos
00564             'UYU' => 'UYP', // Uruguay New Pesos
00565             'CLP' => 'CHP', // Chilean Pesos
00566             'TWD' => 'NTD', // New Taiwan Dollars
00567         );
00568         $currencyCode = Mage::app()->getBaseCurrencyCode();
00569         return isset($codes[$currencyCode]) ? $codes[$currencyCode] : $currencyCode;
00570     }

getResponse (  ) 

Definition at line 728 of file Fedex.php.

00729     {
00730         $statuses = '';
00731         if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result){
00732             if ($trackings = $this->_result->getAllTrackings()) {
00733                 foreach ($trackings as $tracking){
00734                     if($data = $tracking->getAllData()){
00735                         if (!empty($data['status'])) {
00736                             $statuses .= Mage::helper('usa')->__($data['status'])."\n<br/>";
00737                         } else {
00738                             $statuses .= Mage::helper('usa')->__('Empty response')."\n<br/>";
00739                         }
00740                     }
00741                 }
00742             }
00743         }
00744         if (empty($statuses)) {
00745             $statuses = Mage::helper('usa')->__('Empty response');
00746         }
00747         return $statuses;
00748     }

getResult (  ) 

Definition at line 133 of file Fedex.php.

00134     {
00135        return $this->_result;
00136     }

getTracking ( trackings  ) 

Definition at line 573 of file Fedex.php.

00574     {
00575         $this->setTrackingReqeust();
00576 
00577         if (!is_array($trackings)) {
00578             $trackings=array($trackings);
00579         }
00580 
00581         foreach($trackings as $tracking){
00582             $this->_getXMLTracking($tracking);
00583         }
00584 
00585         return $this->_result;
00586     }

setRequest ( Mage_Shipping_Model_Rate_Request request  ) 

Definition at line 62 of file Fedex.php.

00063     {
00064         $this->_request = $request;
00065 
00066         $r = new Varien_Object();
00067 
00068         if ($request->getLimitMethod()) {
00069             $r->setService($request->getLimitMethod());
00070         }
00071 
00072         if ($request->getFedexAccount()) {
00073             $account = $request->getFedexAccount();
00074         } else {
00075             $account = $this->getConfigData('account');
00076         }
00077         $r->setAccount($account);
00078 
00079         if ($request->getFedexDropoff()) {
00080             $dropoff = $request->getFedexDropoff();
00081         } else {
00082             $dropoff = $this->getConfigData('dropoff');
00083         }
00084         $r->setDropoffType($dropoff);
00085 
00086         if ($request->getFedexPackaging()) {
00087             $packaging = $request->getFedexPackaging();
00088         } else {
00089             $packaging = $this->getConfigData('packaging');
00090         }
00091         $r->setPackaging($packaging);
00092 
00093         if ($request->getOrigCountry()) {
00094             $origCountry = $request->getOrigCountry();
00095         } else {
00096             $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
00097         }
00098         $r->setOrigCountry(Mage::getModel('directory/country')->load($origCountry)->getIso2Code());
00099 
00100         if ($request->getOrigPostcode()) {
00101             $r->setOrigPostal($request->getOrigPostcode());
00102         } else {
00103             $r->setOrigPostal(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
00104         }
00105 
00106         if ($request->getDestCountryId()) {
00107             $destCountry = $request->getDestCountryId();
00108         } else {
00109             $destCountry = self::USA_COUNTRY_ID;
00110         }
00111         $r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());
00112 
00113         if ($request->getDestPostcode()) {
00114             $r->setDestPostal($request->getDestPostcode());
00115         } else {
00116 
00117         }
00118 
00119         $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
00120         $r->setWeight($weight);
00121         if ($request->getFreeMethodWeight()!= $request->getPackageWeight()) {
00122             $r->setFreeMethodWeight($request->getFreeMethodWeight());
00123         }
00124 
00125         $r->setValue($request->getPackageValue());
00126         $r->setValueWithDiscount($request->getPackageValueWithDiscount());
00127 
00128         $this->_rawRequest = $r;
00129 
00130         return $this;
00131     }

setTrackingReqeust (  )  [protected]

Definition at line 588 of file Fedex.php.

00589     {
00590         $r = new Varien_Object();
00591 
00592         $account = $this->getConfigData('account');
00593         $r->setAccount($account);
00594 
00595         $this->_rawTrackingRequest = $r;
00596 
00597     }


Member Data Documentation

$_code = 'fedex' [protected]

Reimplemented from Mage_Shipping_Model_Carrier_Abstract.

Definition at line 39 of file Fedex.php.

$_gatewayUrl = 'https://gateway.fedex.com/GatewayDC' [protected]

Definition at line 45 of file Fedex.php.

$_request = null [protected]

Definition at line 41 of file Fedex.php.

$_result = null [protected]

Definition at line 43 of file Fedex.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:55 2009 for Magento by  doxygen 1.5.8