Definition at line 35 of file Dhl.php.
_addRate | ( | $ | shipXml | ) | [protected] |
Definition at line 867 of file Dhl.php.
00868 { 00869 $r = $this->_rawRequest; 00870 $services = $this->getCode('service'); 00871 $regexps = $this->getCode('descr_to_service'); 00872 $desc=(string)$shipXml->EstimateDetail->ServiceLevelCommitment->Desc; 00873 $totalEstimate=(string)$shipXml->EstimateDetail->RateEstimate->TotalChargeEstimate; 00874 /* 00875 * DHL can return with empty result and success code 00876 * we need to make sure there is shipping estimate and code 00877 */ 00878 if($desc && $totalEstimate){ 00879 $service = (string)$shipXml->EstimateDetail->Service->Code; 00880 $description = (string)$shipXml->EstimateDetail->ServiceLevelCommitment->Desc; 00881 if ($service == 'E') { 00882 foreach ($regexps as $expService=>$exp) { 00883 if (preg_match('/'.preg_quote($exp, '/').'/', $description)) { 00884 $service = $expService; 00885 } 00886 } 00887 } 00888 00889 $data['term'] = (isset($services[$service])?$services[$service]:$desc); 00890 $data['price_total'] = $this->getMethodPrice($totalEstimate, $service); 00891 $this->_dhlRates[] = array('service'=>$service, 'data'=>$data); 00892 } 00893 }
_createShipmentXml | ( | $ | shipment, | |
$ | shipKey | |||
) | [protected] |
Definition at line 408 of file Dhl.php.
00409 { 00410 $r = $this->_rawRequest; 00411 00412 $store = Mage::app()->getStore($r->getStoreId()); 00413 00414 $_haz = $this->getConfigFlag('hazardous_materials'); 00415 00416 $_subtotal = $r->getValue(); 00417 $_subtotalWithDiscount = $r->getValueWithDiscount(); 00418 00419 $_width = max(0, (double) $this->getConfigData('default_width')); 00420 $_height = max(0, (double) $this->getConfigData('default_height')); 00421 $_length = max(0, (double) $this->getConfigData('default_length')); 00422 00423 $_apEnabled = $this->getConfigFlag('additional_protection_enabled'); 00424 $_apUseSubtotal = $this->getConfigData('additional_protection_use_subtotal'); 00425 $_apConfigValue = max(0, (double) $this->getConfigData('additional_protection_value')); 00426 $_apMinValue = max(0, (double) $this->getConfigData('additional_protection_min_value')); 00427 $_apValueRounding = $this->getConfigData('additional_protection_rounding'); 00428 00429 $apValue = 0; 00430 $apCode = self::ADDITIONAL_PROTECTION_NOT_REQUIRED; 00431 if ($_apEnabled) { 00432 if ($_apMinValue <= $_subtotal) { 00433 switch ($_apUseSubtotal) { 00434 case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL: 00435 $apValue = $_subtotal; 00436 break; 00437 case self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL_WITH_DISCOUNT: 00438 $apValue = $_subtotalWithDiscount; 00439 break; 00440 default: 00441 case self::ADDITIONAL_PROTECTION_VALUE_CONFIG: 00442 $apValue = $_apConfigValue; 00443 break; 00444 } 00445 00446 if ($apValue) { 00447 $apCode = self::ADDITIONAL_PROTECTION_ASSET; 00448 00449 00450 switch ($_apValueRounding) { 00451 case self::ADDITIONAL_PROTECTION_ROUNDING_CEIL: 00452 $apValue = ceil($apValue); 00453 break; 00454 case self::ADDITIONAL_PROTECTION_ROUNDING_ROUND: 00455 $apValue = round($apValue); 00456 break; 00457 default: 00458 case self::ADDITIONAL_PROTECTION_ROUNDING_FLOOR: 00459 $apValue = floor($apValue); 00460 break; 00461 } 00462 } 00463 } 00464 } 00465 00466 $shipment->addAttribute('action', 'RateEstimate'); 00467 $shipment->addAttribute('version', '1.0'); 00468 00469 $shippingCredentials = $shipment->addChild('ShippingCredentials'); 00470 $shippingCredentials->addChild('ShippingKey',$shipKey); 00471 $shippingCredentials->addChild('AccountNbr', $r->getAccountNbr()); 00472 00473 $shipmentDetail = $shipment->addChild('ShipmentDetail'); 00474 $shipmentDetail->addChild('ShipDate', $r->getShipDate()); 00475 $shipmentDetail->addChild('Service')->addChild('Code', $r->getService()); 00476 $shipmentDetail->addChild('ShipmentType')->addChild('Code', $r->getShipmentType()); 00477 $shipmentDetail->addChild('Weight', $r->getWeight()); 00478 $shipmentDetail->addChild('ContentDesc', $r->getContentDesc()); 00479 $additionalProtection = $shipmentDetail->addChild('AdditionalProtection'); 00480 $additionalProtection->addChild('Code', $apCode); 00481 $additionalProtection->addChild('Value', floor($apValue)); 00482 00483 if ($_width && $_height && $_length) { 00484 $dimensions = $shipmentDetail->addChild('Dimensions'); 00485 $dimensions->addChild('Length', $_length); 00486 $dimensions->addChild('Width', $_width); 00487 $dimensions->addChild('Height', $_height); 00488 } 00489 00490 if ($_haz || ($r->getExtendedService())) { 00491 $specialServices = $shipmentDetail->addChild('SpecialServices'); 00492 } 00493 00494 if ($_haz) { 00495 $hazardousMaterials = $specialServices->addChild('SpecialService'); 00496 $hazardousMaterials->addChild('Code', 'HAZ'); 00497 } 00498 00499 if ($r->getExtendedService()) { 00500 $extendedService = $specialServices->addChild('SpecialService'); 00501 $extendedService->addChild('Code', $r->getExtendedService()); 00502 } 00503 00504 00505 /* 00506 * R = Receiver (if receiver, need AccountNbr) 00507 * S = Sender 00508 * 3 = Third Party (if third party, need AccountNbr) 00509 */ 00510 $billing = $shipment->addChild('Billing'); 00511 $billing->addChild('Party')->addChild('Code', 'S'); 00512 $billing->addChild('DutyPaymentType',$r->getDutyPaymentType()); 00513 00514 /* 00515 $cod = $billing->addChild('CODPayment'); 00516 $cod->addChild('Code', 'P'); 00517 $cod->addChild('Value', 100); 00518 */ 00519 00520 00521 $receiverAddress = $shipment->addChild('Receiver')->addChild('Address'); 00522 $receiverAddress->addChild('Street', htmlspecialchars($r->getDestStreet()?$r->getDestStreet():'NA')); 00523 $receiverAddress->addChild('City', htmlspecialchars($r->getDestCity())); 00524 $receiverAddress->addChild('State', htmlspecialchars($r->getDestState())); 00525 /* 00526 * DHL xml service is using UK for united kingdom instead of GB which is a standard ISO country code 00527 */ 00528 $receiverAddress->addChild('Country', ($r->getDestCountryId()=='GB'?'UK':$r->getDestCountryId())); 00529 $receiverAddress->addChild('PostalCode', $r->getDestPostal()); 00530 /* 00531 $special_service=$this->getCode('special_service'); 00532 if(array_key_exists($r->getService(),$special_service)){ 00533 $specialService = $shipment->addChild('SpecialServices')->addChild('SpecialService'); 00534 $specialService->addChild('Code',$special_service[$r->getService()]); 00535 } 00536 */ 00537 }
_getQuotes | ( | ) | [protected] |
_getShipDate | ( | $ | domestic = true |
) | [protected] |
Definition at line 289 of file Dhl.php.
00290 { 00291 if ($domestic) { 00292 $days = explode(',', $this->getConfigData('shipment_days')); 00293 } else { 00294 $days = explode(',', $this->getConfigData('intl_shipment_days')); 00295 } 00296 00297 if (!$days) { 00298 return date('Y-m-d'); 00299 } 00300 00301 $i=0; 00302 $weekday = date('w'); 00303 while(!in_array($weekday, $days) && $i < 10) { 00304 $i++; 00305 $weekday = date('w', strtotime("+$i day")); 00306 } 00307 00308 return date('Y-m-d', strtotime("+$i day")); 00309 }
_getXmlQuotes | ( | ) | [protected] |
Definition at line 311 of file Dhl.php.
00312 { 00313 $r = $this->_rawRequest; 00314 00315 $xml = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><eCommerce/>'); 00316 $xml->addAttribute('action', 'Request'); 00317 $xml->addAttribute('version', '1.1'); 00318 00319 $requestor = $xml->addChild('Requestor'); 00320 $requestor->addChild('ID', $r->getId()); 00321 $requestor->addChild('Password', $r->getPassword()); 00322 00323 $methods = explode(',', $this->getConfigData('allowed_methods')); 00324 $internationcode = $this->getCode('international_searvice'); 00325 $hasShipCode = false; 00326 00327 $shipDate = $this->_getShipDate(); 00328 00329 if ($r->hasService() && $r->getFreeMethodRequest()) { 00330 if ($r->getDestCountryId() == self::USA_COUNTRY_ID) { 00331 $shipment = $xml->addChild('Shipment'); 00332 $shipKey=$r->getShippingKey(); 00333 $r->setShipDate($shipDate); 00334 } else { 00335 $shipment = $xml->addChild('IntlShipment'); 00336 $shipKey=$r->getShippingIntlKey(); 00337 $r->setShipDate($this->_getShipDate(false)); 00338 /* 00339 * For internation shippingment customsvalue must be posted 00340 */ 00341 $shippingDuty = $shipment->addChild('Dutiable'); 00342 $shippingDuty->addChild('DutiableFlag',($r->getDutiable()?'Y':'N')); 00343 $shippingDuty->addChild('CustomsValue',$r->getValue()); 00344 } 00345 $hasShipCode = true; 00346 $this->_createShipmentXml($shipment,$shipKey); 00347 } else { 00348 foreach ($methods as $method) { 00349 $shipment = false; 00350 if (in_array($method, array_keys($this->getCode('special_express')))) { 00351 $r->setService('E'); 00352 $r->setExtendedService($this->getCode('special_express', $method)); 00353 } else { 00354 $r->setService($method); 00355 $r->setExtendedService(null); 00356 } 00357 if ($r->getDestCountryId() == self::USA_COUNTRY_ID && $method!=$internationcode) { 00358 $shipment = $xml->addChild('Shipment'); 00359 $shipKey=$r->getShippingKey(); 00360 $r->setShipDate($shipDate); 00361 }elseif($r->getDestCountryId() != self::USA_COUNTRY_ID && $method==$internationcode){ 00362 $shipment = $xml->addChild('IntlShipment'); 00363 $shipKey=$r->getShippingIntlKey(); 00364 $r->setShipDate($this->_getShipDate(false)); 00365 00366 /* 00367 * For internation shippingment customsvalue must be posted 00368 */ 00369 $shippingDuty = $shipment->addChild('Dutiable'); 00370 $shippingDuty->addChild('DutiableFlag',($r->getDutiable()?'Y':'N')); 00371 $shippingDuty->addChild('CustomsValue',$r->getValue()); 00372 } 00373 if ($shipment!==false) { 00374 $hasShipCode = true; 00375 $this->_createShipmentXml($shipment,$shipKey); 00376 } 00377 } 00378 } 00379 00380 if (!$hasShipCode) { 00381 $this->_errors[] = Mage::helper('usa')->__('There is no available method for selected shipping address.'); 00382 return; 00383 } 00384 00385 $request = $xml->asXML(); 00386 00387 try { 00388 $url = $this->getConfigData('gateway_url'); 00389 if (!$url) { 00390 $url = $this->_defaultGatewayUrl; 00391 } 00392 $ch = curl_init(); 00393 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 00394 curl_setopt($ch, CURLOPT_URL, $url); 00395 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 00396 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 00397 curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 00398 $responseBody = curl_exec($ch); 00399 curl_close ($ch); 00400 } catch (Exception $e) { 00401 $responseBody = ''; 00402 } 00403 $res = $this->_parseXmlResponse($responseBody); 00404 00405 return $res; 00406 }
_getXMLTracking | ( | $ | trackings | ) | [protected] |
Definition at line 920 of file Dhl.php.
00921 { 00922 $r = $this->_rawTrackRequest; 00923 00924 $xml = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><eCommerce/>'); 00925 $xml->addAttribute('action', 'Request'); 00926 $xml->addAttribute('version', '1.1'); 00927 00928 $requestor = $xml->addChild('Requestor'); 00929 $requestor->addChild('ID', $r->getId()); 00930 $requestor->addChild('Password', $r->getPassword()); 00931 00932 $track=$xml->addChild('Track'); 00933 $track->addAttribute('action', 'Get'); 00934 $track->addAttribute('version', '1.0'); 00935 00936 //shippment has not been delivered or no scans 00937 //$track->addChild('Shipment')->addChild('TrackingNbr','1231230011'); 00938 //home shipment 00939 //$track->addChild('Shipment')->addChild('TrackingNbr','2342340011'); 00940 //international shipment 00941 //$track->addChild('Shipment')->addChild('TrackingNbr','5675670011'); 00942 //tracking not in airborme tracking tsystem 00943 //$track->addChild('Shipment')->addChild('TrackingNbr','7897890011'); 00944 //tracking need to contanct customer service for more information 00945 //$track->addChild('Shipment')->addChild('TrackingNbr','8198190011'); 00946 00947 foreach($trackings as $tracking){ 00948 $track->addChild('Shipment')->addChild('TrackingNbr',$tracking); 00949 } 00950 $request = $xml->asXML(); 00951 /* 00952 * tracking api cannot process from 3pm to 5pm PST time on Sunday 00953 * DHL Airborne conduts a maintainance during that period. 00954 */ 00955 try { 00956 $url = $this->getConfigData('gateway_url'); 00957 if (!$url) { 00958 $url = $this->_defaultGatewayUrl; 00959 } 00960 $ch = curl_init(); 00961 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 00962 curl_setopt($ch, CURLOPT_URL, $url); 00963 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 00964 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 00965 curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 00966 $responseBody = curl_exec($ch); 00967 curl_close ($ch); 00968 } catch (Exception $e) { 00969 $responseBody = ''; 00970 } 00971 #echo "<xmp>".$responseBody."</xmp>"; 00972 $this->_parseXmlTrackingResponse($trackings, $responseBody); 00973 }
_parseXmlObject | ( | $ | shipXml | ) | [protected] |
Definition at line 613 of file Dhl.php.
00614 { 00615 if( 00616 is_object($shipXml->Faults) 00617 && is_object($shipXml->Faults->Fault) 00618 && is_object($shipXml->Faults->Fault->Desc) 00619 && intval($shipXml->Faults->Fault->Code) != self::SUCCESS_CODE 00620 ) { 00621 $code = (string)$shipXml->Faults->Fault->Code; 00622 $description = $shipXml->Faults->Fault->Desc; 00623 $this->_errors[$code] = Mage::helper('usa')->__('Error #%s: %s', $code, $description); 00624 } elseif( 00625 is_object($shipXml->Faults) 00626 && is_object($shipXml->Result->Code) 00627 && is_object($shipXml->Result->Desc) 00628 && intval($shipXml->Result->Code) != self::SUCCESS_CODE 00629 ) { 00630 $code = (string)$shipXml->Result->Code; 00631 $description = $shipXml->Result->Desc; 00632 $this->_errors[$code] = Mage::helper('usa')->__('Error #%s: %s', $code, $description); 00633 }else { 00634 $this->_addRate($shipXml); 00635 } 00636 return $this; 00637 }
_parseXmlResponse | ( | $ | response | ) | [protected] |
Definition at line 539 of file Dhl.php.
00540 { 00541 $r = $this->_rawRequest; 00542 $costArr = array(); 00543 $priceArr = array(); 00544 $errorTitle = 'Unable to retrieve quotes'; 00545 00546 $tr = get_html_translation_table(HTML_ENTITIES); 00547 unset($tr['<'], $tr['>'], $tr['"']); 00548 $response = str_replace(array_keys($tr), array_values($tr), $response); 00549 00550 if (strlen(trim($response))>0) { 00551 if (strpos(trim($response), '<?xml')===0) { 00552 $xml = simplexml_load_string($response); 00553 if (is_object($xml)) { 00554 if ( 00555 is_object($xml->Faults) 00556 && is_object($xml->Faults->Fault) 00557 && is_object($xml->Faults->Fault->Code) 00558 && is_object($xml->Faults->Fault->Description) 00559 && is_object($xml->Faults->Fault->Context) 00560 ) { 00561 $code = (string)$xml->Faults->Fault->Code; 00562 $description = $xml->Faults->Fault->Description; 00563 $context = $xml->Faults->Fault->Context; 00564 $this->_errors[$code] = Mage::helper('usa')->__('Error #%s : %s (%s)', $code, $description, $context); 00565 } else { 00566 if ($r->getDestCountryId() == self::USA_COUNTRY_ID) { 00567 if ($xml->Shipment) { 00568 foreach($xml->Shipment as $shipXml){ 00569 $this->_parseXmlObject($shipXml); 00570 } 00571 } else { 00572 $this->_errors[] = Mage::helper('usa')->__('Shipment is not available.'); 00573 } 00574 } else { 00575 $shipXml = $xml->IntlShipment; 00576 $this->_parseXmlObject($shipXml); 00577 } 00578 $shipXml=(($r->getDestCountryId() == self::USA_COUNTRY_ID)?$xml->Shipment:$xml->IntlShipment); 00579 } 00580 } 00581 } else { 00582 $this->_errors[] = Mage::helper('usa')->__('Response is in the wrong format'); 00583 } 00584 } 00585 00586 $result = Mage::getModel('shipping/rate_result'); 00587 00588 foreach ($this->_errors as $errorText) { 00589 $error = Mage::getModel('shipping/rate_result_error'); 00590 $error->setCarrier('dhl'); 00591 $error->setCarrierTitle($this->getConfigData('title')); 00592 //$error->setErrorMessage($errorText); 00593 $error->setErrorMessage($this->getConfigData('specificerrmsg')); 00594 $result->append($error); 00595 } 00596 00597 foreach($this->_dhlRates as $rate) { 00598 $method = $rate['service']; 00599 $data = $rate['data']; 00600 $rate = Mage::getModel('shipping/rate_result_method'); 00601 $rate->setCarrier('dhl'); 00602 $rate->setCarrierTitle($this->getConfigData('title')); 00603 $rate->setMethod($method); 00604 $rate->setMethodTitle($data['term']); 00605 $rate->setCost($data['price_total']); 00606 $rate->setPrice($data['price_total']); 00607 $result->append($rate); 00608 } 00609 return $result; 00610 00611 }
_parseXmlTrackingResponse | ( | $ | trackings, | |
$ | response | |||
) | [protected] |
Definition at line 975 of file Dhl.php.
00976 { 00977 $errorTitle = 'Unable to retrieve tracking'; 00978 $resultArr=array(); 00979 $errorArr=array(); 00980 $trackingserror=array(); 00981 $tracknum=''; 00982 if (strlen(trim($response))>0) { 00983 if (strpos(trim($response), '<?xml')===0) { 00984 $xml = simplexml_load_string($response); 00985 if (is_object($xml)) { 00986 $trackxml=$xml->Track; 00987 if ( 00988 is_object($xml->Faults) 00989 && is_object($xml->Faults->Fault) 00990 && is_object($xml->Faults->Fault->Code) 00991 && is_object($xml->Faults->Fault->Description) 00992 && is_object($xml->Faults->Fault->Context) 00993 ) { 00994 $code = (string)$xml->Faults->Fault->Code; 00995 $description = $xml->Faults->Fault->Description; 00996 $context = $xml->Faults->Fault->Context; 00997 $errorTitle = Mage::helper('usa')->__('Error #%s : %s (%s)', $code, $description, $context); 00998 }elseif(is_object($trackxml) && is_object($trackxml->Shipment)){ 00999 foreach($trackxml->Shipment as $txml){ 01000 $rArr=array(); 01001 01002 if(is_object($txml)){ 01003 $tracknum=(string)$txml->TrackingNbr; 01004 if($txml->Fault){ 01005 $code = (string)$txml->Fault->Code; 01006 $description = $txml->Fault->Description; 01007 $errorArr[$tracknum] = Mage::helper('usa')->__('Error #%s: %s', $code, $description); 01008 }elseif($txml->Result){ 01009 $code = (int)$txml->Result->Code; 01010 if($code===0){ 01011 /* 01012 * Code 0== airbill found 01013 */ 01014 $rArr['service']=(string)$txml->Service->Desc; 01015 if(isset($txml->Weight)) 01016 $rArr['weight']=(string)$txml->Weight." lbs"; 01017 if (isset($txml->Delivery)) { 01018 $rArr['deliverydate'] = (string)$txml->Delivery->Date; 01019 $rArr['deliverytime'] = (string)$txml->Delivery->Time.':00'; 01020 $rArr['status'] = Mage::helper('usa')->__('Delivered'); 01021 if (isset($txml->Delivery->Location->Desc)) { 01022 $rArr['deliverylocation'] = (string)$txml->Delivery->Location->Desc; 01023 } 01024 } elseif (isset($txml->Pickup)) { 01025 $rArr['deliverydate'] = (string)$txml->Pickup->Date; 01026 $rArr['deliverytime'] = (string)$txml->Pickup->Time.':00'; 01027 $rArr['status'] = Mage::helper('usa')->__('Shipment picked up'); 01028 } else { 01029 $rArr['status']=(string)$txml->ShipmentType->Desc.Mage::helper('usa')->__(' was not delivered nor scanned'); 01030 } 01031 01032 $packageProgress = array(); 01033 if (isset($txml->TrackingHistory) && isset($txml->TrackingHistory->Status)) { 01034 01035 foreach ($txml->TrackingHistory->Status as $thistory) { 01036 $tempArr=array(); 01037 $tempArr['activity'] = (string)$thistory->StatusDesc; 01038 $tempArr['deliverydate'] = (string)$thistory->Date;//YYYY-MM-DD 01039 $tempArr['deliverytime'] = (string)$thistory->Time.':00';//HH:MM:ss 01040 $addArr=array(); 01041 if (isset($thistory->Location->City)) { 01042 $addArr[] = (string)$thistory->Location->City; 01043 } 01044 if (isset($thistory->Location->State)) { 01045 $addArr[] = (string)$thistory->Location->State; 01046 } 01047 if (isset($thistory->Location->CountryCode)) { 01048 $addArr[] = (string)$thistory->Location->Country; 01049 } 01050 if ($addArr) { 01051 $tempArr['deliverylocation']=implode(', ',$addArr); 01052 }elseif(isset($thistory['final_delivery']) && (string)$thistory['final_delivery']==='true'){ 01053 /* 01054 if the history is final delivery, there is no informationabout city, state and country 01055 */ 01056 $addArr=array(); 01057 if (isset($txml->Receiver->City)) { 01058 $addArr[] = (string)$txml->Receiver->City; 01059 } 01060 if (isset($thistory->Receiver->State)) { 01061 $addArr[] = (string)$txml->Receiver->State; 01062 } 01063 if (isset($thistory->Receiver->CountryCode)) { 01064 $addArr[] = (string)$txml->Receiver->Country; 01065 } 01066 $tempArr['deliverylocation']=implode(', ',$addArr); 01067 } 01068 $packageProgress[] = $tempArr; 01069 } 01070 $rArr['progressdetail'] = $packageProgress; 01071 01072 } 01073 $resultArr[$tracknum]=$rArr; 01074 }else{ 01075 $description =(string)$txml->Result->Desc; 01076 if($description) 01077 $errorArr[$tracknum]=Mage::helper('usa')->__('Error #%s: %s', $code, $description); 01078 else 01079 $errorArr[$tracknum]=Mage::helper('usa')->__('Unable to retrieve tracking'); 01080 } 01081 }else{ 01082 $errorArr[$tracknum]=Mage::helper('usa')->__('Unable to retrieve tracking'); 01083 } 01084 01085 } 01086 } 01087 01088 } 01089 } 01090 } else { 01091 $errorTitle = Mage::helper('usa')->__('Response is in the wrong format'); 01092 } 01093 } 01094 01095 $result = Mage::getModel('shipping/tracking_result'); 01096 if($errorArr || $resultArr){ 01097 foreach ($errorArr as $t=>$r) { 01098 $error = Mage::getModel('shipping/tracking_result_error'); 01099 $error->setCarrier('dhl'); 01100 $error->setCarrierTitle($this->getConfigData('title')); 01101 $error->setTracking($t); 01102 $error->setErrorMessage($r); 01103 $result->append($error); 01104 } 01105 01106 foreach($resultArr as $t => $data) { 01107 $tracking = Mage::getModel('shipping/tracking_result_status'); 01108 $tracking->setCarrier('dhl'); 01109 $tracking->setCarrierTitle($this->getConfigData('title')); 01110 $tracking->setTracking($t); 01111 $tracking->addData($data); 01112 /* 01113 $tracking->setStatus($data['status']); 01114 $tracking->setService($data['service']); 01115 if(isset($data['deliverydate'])) $tracking->setDeliveryDate($data['deliverydate']); 01116 if(isset($data['deliverytime'])) $tracking->setDeliveryTime($data['deliverytime']); 01117 */ 01118 $result->append($tracking); 01119 } 01120 }else{ 01121 foreach($trackings as $t){ 01122 $error = Mage::getModel('shipping/tracking_result_error'); 01123 $error->setCarrier('dhl'); 01124 $error->setCarrierTitle($this->getConfigData('title')); 01125 $error->setTracking($t); 01126 $error->setErrorMessage($errorTitle); 01127 $result->append($error); 01128 01129 } 01130 } 01131 $this->_result = $result; 01132 //echo "<pre>";print_r($result); 01133 01134 }
_setFreeMethodRequest | ( | $ | freeMethod | ) | [protected] |
Definition at line 264 of file Dhl.php.
00265 { 00266 $r = $this->_rawRequest; 00267 00268 $r->setFreeMethodRequest(true); 00269 $weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight()); 00270 $freeWeight = round(max(1, $weight),0); 00271 $r->setWeight($freeWeight); 00272 $r->setService($freeMethod); 00273 }
collectRates | ( | Mage_Shipping_Model_Rate_Request $ | request | ) |
Reimplemented from Mage_Shipping_Model_Carrier_Abstract.
Definition at line 66 of file Dhl.php.
00067 { 00068 if (!$this->getConfigFlag('active')) { 00069 return false; 00070 } 00071 00072 $this->setRequest($request); 00073 00074 $this->_result = $this->_getQuotes(); 00075 00076 $this->_updateFreeMethodQuote($request); 00077 00078 return $this->getResult(); 00079 }
getAdditionalProtectionRoundingTypes | ( | ) |
Definition at line 1187 of file Dhl.php.
01188 { 01189 return array( 01190 self::ADDITIONAL_PROTECTION_ROUNDING_FLOOR => Mage::helper('usa')->__('To lower'), 01191 self::ADDITIONAL_PROTECTION_ROUNDING_CEIL => Mage::helper('usa')->__('To upper'), 01192 self::ADDITIONAL_PROTECTION_ROUNDING_ROUND => Mage::helper('usa')->__('Round'), 01193 ); 01194 }
getAdditionalProtectionValueTypes | ( | ) |
Definition at line 1178 of file Dhl.php.
01179 { 01180 return array( 01181 self::ADDITIONAL_PROTECTION_VALUE_CONFIG=>Mage::helper('usa')->__('Configuration'), 01182 self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL=>Mage::helper('usa')->__('Subtotal'), 01183 self::ADDITIONAL_PROTECTION_VALUE_SUBTOTAL_WITH_DISCOUNT=>Mage::helper('usa')->__('Subtotal With Discount'), 01184 ); 01185 }
getAllowedMethods | ( | ) |
Get allowed shipping methods
Implements Mage_Shipping_Model_Carrier_Interface.
Definition at line 1163 of file Dhl.php.
01164 { 01165 $allowed = explode(',', $this->getConfigData('allowed_methods')); 01166 $arr = array(); 01167 foreach ($allowed as $k) { 01168 $arr[$k] = $this->getCode('service', $k); 01169 } 01170 return $arr; 01171 }
getCode | ( | $ | type, | |
$ | code = '' | |||
) |
Definition at line 789 of file Dhl.php.
00790 { 00791 static $codes; 00792 $codes = array( 00793 'service'=>array( 00794 'IE' => Mage::helper('usa')->__('International Express'), 00795 'E SAT' => Mage::helper('usa')->__('Express Saturday'), 00796 'E 10:30AM' => Mage::helper('usa')->__('Express 10:30 AM'), 00797 'E' => Mage::helper('usa')->__('Express'), 00798 'N' => Mage::helper('usa')->__('Next Afternoon'), 00799 'S' => Mage::helper('usa')->__('Second Day Service'), 00800 'G' => Mage::helper('usa')->__('Ground'), 00801 ), 00802 'shipment_type'=>array( 00803 'L' => Mage::helper('usa')->__('Letter'), 00804 'P' => Mage::helper('usa')->__('Package'), 00805 ), 00806 'international_searvice'=>'IE', 00807 /* 00808 'special_service'=>array( 00809 'E SAT'=>'SAT', 00810 'E 10:30AM'=>'1030', 00811 ), 00812 */ 00813 'dutypayment_type'=>array( 00814 'S' => Mage::helper('usa')->__('Sender'), 00815 'R' => Mage::helper('usa')->__('Receiver'), 00816 '3' => Mage::helper('usa')->__('Third Party'), 00817 ), 00818 00819 'special_express'=>array( 00820 'E SAT'=>'SAT', 00821 'E 10:30AM'=>'1030', 00822 ), 00823 00824 'descr_to_service'=>array( 00825 'E SAT'=>'Saturday', 00826 'E 10:30AM'=>'10:30 A.M', 00827 ), 00828 00829 ); 00830 00831 00832 00833 if (!isset($codes[$type])) { 00834 // throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid DHL XML code type: %s', $type)); 00835 return false; 00836 } elseif (''===$code) { 00837 return $codes[$type]; 00838 } 00839 00840 if (!isset($codes[$type][$code])) { 00841 // throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid DHL XML code for type %s: %s', $type, $code)); 00842 return false; 00843 } else { 00844 return $codes[$type][$code]; 00845 } 00846 }
getResponse | ( | ) |
Definition at line 1136 of file Dhl.php.
01137 { 01138 $statuses = ''; 01139 if ($this->_result instanceof Mage_Shipping_Model_Tracking_Result){ 01140 if ($trackings = $this->_result->getAllTrackings()) { 01141 foreach ($trackings as $tracking){ 01142 if($data = $tracking->getAllData()){ 01143 if (isset($data['status'])) { 01144 $statuses .= Mage::helper('usa')->__($data['status'])."\n<br/>"; 01145 } else { 01146 $statuses .= Mage::helper('usa')->__($data['error_message'])."\n<br/>"; 01147 } 01148 } 01149 } 01150 } 01151 } 01152 if (empty($statuses)) { 01153 $statuses = Mage::helper('usa')->__('Empty response'); 01154 } 01155 return $statuses; 01156 }
getResult | ( | ) |
Definition at line 232 of file Dhl.php.
00233 { 00234 return $this->_result; 00235 // $result = Mage::getModel('shipping/rate_result'); 00236 // 00237 // foreach ($this->_errors as $errorText) { 00238 // $error = Mage::getModel('shipping/rate_result_error'); 00239 // $error->setCarrier('dhl'); 00240 // $error->setCarrierTitle($this->getConfigData('title')); 00241 // $error->setErrorMessage($errorText); 00242 // $result->append($error); 00243 // } 00244 // 00245 // foreach($this->_dhlRates as $method => $data) { 00246 // $rate = Mage::getModel('shipping/rate_result_method'); 00247 // $rate->setCarrier('dhl'); 00248 // $rate->setCarrierTitle($this->getConfigData('title')); 00249 // $rate->setMethod($method); 00250 // $rate->setMethodTitle($data['term']); 00251 // $rate->setCost($data['price_total']); 00252 // $rate->setPrice($data['price_total']); 00253 // $result->append($rate); 00254 // } 00255 // 00256 // return $result; 00257 }
getTracking | ( | $ | trackings | ) |
Definition at line 895 of file Dhl.php.
00896 { 00897 $this->setTrackingReqeust(); 00898 00899 if (!is_array($trackings)) { 00900 $trackings=array($trackings); 00901 } 00902 $this->_getXMLTracking($trackings); 00903 00904 return $this->_result; 00905 }
isStateProvinceRequired | ( | ) |
setRequest | ( | Mage_Shipping_Model_Rate_Request $ | request | ) |
Definition at line 81 of file Dhl.php.
00082 { 00083 $this->_request = $request; 00084 00085 $r = new Varien_Object(); 00086 00087 $r->setStoreId($request->getStoreId()); 00088 00089 if ($request->getLimitMethod()) { 00090 $r->setService($request->getLimitMethod()); 00091 } 00092 00093 if ($request->getDhlId()) { 00094 $id = $request->getDhlId(); 00095 } else { 00096 $id = $this->getConfigData('id'); 00097 } 00098 $r->setId($id); 00099 00100 if ($request->getDhlPassword()) { 00101 $password = $request->getDhlPassword(); 00102 } else { 00103 $password = $this->getConfigData('password'); 00104 } 00105 $r->setPassword($password); 00106 00107 if ($request->getDhlAccount()) { 00108 $accountNbr = $request->getDhlAccount(); 00109 } else { 00110 $accountNbr = $this->getConfigData('account'); 00111 } 00112 $r->setAccountNbr($accountNbr); 00113 00114 if ($request->getDhlShippingKey()) { 00115 $shippingKey = $request->getDhlShippingKey(); 00116 } else { 00117 $shippingKey = $this->getConfigData('shipping_key'); 00118 } 00119 $r->setShippingKey($shippingKey); 00120 00121 if ($request->getDhlShippingIntlKey()) { 00122 $shippingKey = $request->getDhlShippingIntlKey(); 00123 } else { 00124 $shippingKey = $this->getConfigData('shipping_intlkey'); 00125 } 00126 $r->setShippingIntlKey($shippingKey); 00127 00128 if ($request->getDhlShipmentType()) { 00129 $shipmentType = $request->getDhlShipmentType(); 00130 } else { 00131 $shipmentType = $this->getConfigData('shipment_type'); 00132 } 00133 $r->setShipmentType($shipmentType); 00134 00135 if($request->getDhlDutiable()){ 00136 $shipmentDutible = $request->getDhlDutiable(); 00137 }else{ 00138 $shipmentDutible = $this->getConfigData('dutiable'); 00139 } 00140 $r->setDutiable($shipmentDutible); 00141 00142 if($request->getDhlDutyPaymentType()){ 00143 $dutypaytype = $request->getDhlDutyPaymentType(); 00144 }else{ 00145 $dutypaytype = $this->getConfigData('dutypaymenttype'); 00146 } 00147 $r->setDutyPaymentType($dutypaytype); 00148 00149 if($request->getDhlContentDesc()){ 00150 $contentdesc = $request->getDhlContentDesc(); 00151 }else{ 00152 $contentdesc = $this->getConfigData('contentdesc'); 00153 } 00154 $r->setContentDesc($contentdesc); 00155 00156 if ($request->getDestPostcode()) { 00157 $r->setDestPostal($request->getDestPostcode()); 00158 } 00159 00160 if ($request->getOrigCountry()) { 00161 $origCountry = $request->getOrigCountry(); 00162 } else { 00163 $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore()); 00164 } 00165 $r->setOrigCountry($origCountry); 00166 00167 /* 00168 * DHL only accepts weight as a whole number. Maximum length is 3 digits. 00169 */ 00170 $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); 00171 $shippingWeight = round(max(1, $weight),0); 00172 00173 $r->setValue(round($request->getPackageValue(),2)); 00174 $r->setValueWithDiscount($request->getPackageValueWithDiscount()); 00175 $r->setDestStreet(Mage::helper('core/string')->substr($request->getDestStreet(), 0, 35)); 00176 $r->setDestCity($request->getDestCity()); 00177 00178 if ($request->getDestCountryId()) { 00179 $destCountry = $request->getDestCountryId(); 00180 } else { 00181 $destCountry = self::USA_COUNTRY_ID; 00182 } 00183 00184 //for DHL, puero rico state for US will assume as puerto rico country 00185 //for puerto rico, dhl will ship as international 00186 if ($destCountry==self::USA_COUNTRY_ID && ($request->getDestPostcode()=='00912' || $request->getDestRegionCode()==self::PUERTORICO_COUNTRY_ID)) { 00187 $destCountry = self::PUERTORICO_COUNTRY_ID; 00188 } 00189 00190 $r->setDestCountryId($destCountry); 00191 $r->setDestState( $request->getDestRegionCode()); 00192 00193 $r->setWeight($shippingWeight); 00194 $r->setFreeMethodWeight($request->getFreeMethodWeight()); 00195 $this->_rawRequest = $r; 00196 // $methods = explode(',', $this->getConfigData('allowed_methods')); 00197 // 00198 // $freeMethod = $this->getConfigData('free_method'); 00199 // 00200 // $internationcode = $this->getCode('international_searvice'); 00201 00202 00203 00204 // $minOrderAmount = $this->getConfigData('cutoff_cost') ? $this->getConfigData('cutoff_cost') : 0; 00205 // if ($shippingWeight>0) { 00206 // $this->_rawRequest->setWeight($shippingWeight); 00207 // $this->_getQuotes(); 00208 // foreach ($methods as $method) { 00209 // if(($method==$internationcode && ($r->getDestCountryId() != self::USA_COUNTRY_ID)) || 00210 // ($method!=$internationcode && ($r->getDestCountryId() == self::USA_COUNTRY_ID))) 00211 // { 00212 // $weight = $freeMethod==$method && $this->getConfigData('cutoff_cost') <= $r->getValue() ? 0 : $shippingWeight; 00213 // if ($weight>0) { 00214 // $this->_rawRequest->setWeight($weight); 00215 // $this->_rawRequest->setService($method); 00216 // $this->_getQuotes(); 00217 // } else { 00218 // $this->_dhlRates[$method] = array( 00219 // 'term' => $this->getCode('service', $method), 00220 // 'price_total' => 0, 00221 // ); 00222 // } 00223 // } 00224 // } 00225 // } else { 00226 // $this->_errors[] = Mage::helper('usa')->__('Please enter the package weight'); 00227 // } 00228 00229 return $this; 00230 }
setTrackingReqeust | ( | ) | [protected] |
Definition at line 907 of file Dhl.php.
00908 { 00909 $r = new Varien_Object(); 00910 00911 $id = $this->getConfigData('id'); 00912 $r->setId($id); 00913 00914 $password = $this->getConfigData('password'); 00915 $r->setPassword($password); 00916 00917 $this->_rawTrackRequest = $r; 00918 }
$_code = 'dhl' [protected] |
$_defaultGatewayUrl = 'https://eCommerce.airborne.com/ApiLandingTest.asp' [protected] |
const ADDITIONAL_PROTECTION_ASSET = 'AP' |
const ADDITIONAL_PROTECTION_NOT_REQUIRED = 'NR' |
const ADDITIONAL_PROTECTION_ROUNDING_CEIL = 1 |
const ADDITIONAL_PROTECTION_ROUNDING_FLOOR = 0 |
const ADDITIONAL_PROTECTION_ROUNDING_ROUND = 2 |
const ADDITIONAL_PROTECTION_VALUE_CONFIG = 0 |
const ADDITIONAL_PROTECTION_VALUE_SUBTOTAL = 1 |
const SUCCESS_CODE = 203 |