Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

UPS XML Time in Transit -HELP!


ukgoods

Recommended Posts

I am trying to update the UPS XML contribution to include Ground Time in Transit.

 

I have it returning the XML response from UPS. However, I cannot parse it properly. Can someone tell me why my function is not returning the number of days?

 

I am a newbie at PHP and UPS will not provide programming help.

 

Here is the response which is returned from UPS:

 

<?xml version="1.0"?>

<TimeInTransitResponse>

<Response>

<TransactionReference>

<CustomerContext>TNT_D Origin Country Code</CustomerContext>

<XpciVersion>1.0002</XpciVersion>

</TransactionReference>

<ResponseStatusCode>1</ResponseStatusCode>

<ResponseStatusDescription>Success</ResponseStatusDescription>

</Response>

<TransitResponse>

<PickupDate>2004-06-30</PickupDate>

<TransitFrom>

<AddressArtifactFormat>

<PoliticalDivision2>MILTON</PoliticalDivision2>

<PoliticalDivision1>DE</PoliticalDivision1>

<Country>UNITED STATES</Country>

<CountryCode>US</CountryCode>

<PostcodePrimaryLow>19968</PostcodePrimaryLow>

</AddressArtifactFormat>

</TransitFrom>

<TransitTo>

<AddressArtifactFormat>

<PoliticalDivision2>ASTON</PoliticalDivision2>

<PoliticalDivision1>PA</PoliticalDivision1>

<Country>UNITED STATES</Country>

<CountryCode>US</CountryCode>

<PostcodePrimaryLow>19014</PostcodePrimaryLow>

</AddressArtifactFormat>

</TransitTo>

<ShipmentWeight>

<UnitOfMeasurement>

<Code>LBS</Code>

</UnitOfMeasurement>

<Weight>23.0</Weight>

</ShipmentWeight>

<Disclaimer>All services are guaranteed if shipment is paid for in full by a payee

in the United States. Services listed as guaranteed are backed by a money-back

guarantee for transportation charges only. See Terms and Conditions in the Service

Guide for details. Certain commoditites and high value shipments may require

additional transit time for customs clearance.</Disclaimer>

<ServiceSummary>

<Service>

<Code>GND</Code>

<Description>UPS Ground</Description>

</Service>

<Guaranteed>

<Code>Y</Code>

</Guaranteed>

<EstimatedArrival>

<BusinessTransitDays>1</BusinessTransitDays>

<Time>08:30:00</Time>

<PickupDate>2004-06-30</PickupDate>

<PickupTime>16:00:00</PickupTime>

<HolidayCount>0</HolidayCount>

<DelayCount>0</DelayCount>

<Date>2004-06-30</Date>

<DayOfWeek>WED</DayOfWeek>

<TotalTransitDays>1</TotalTransitDays>

<CustomerCenterCutoff>15:00:00</CustomerCenterCutoff>

<RestDays>1</RestDays>

</EstimatedArrival>

</ServiceSummary>

 

Here is my parsing function:

 

// Parse XML message returned by the UPS post server.

function _transitparseResult($xmlResult) {

$doc = new XMLDocument();

$xp = new XMLParser();

$xp->setDocument($doc);

$xp->parse($xmlResult);

$doc = $xp->getDocument();

 

// Get version. Must be xpci version 1.0001 or this might not work.

$responseVersion = $doc->getValueByPath('TimeInTransitResponse/Response/TransactionReference/XpciVersion');

if ($this->transitxpci_version != $responseVersion) {

$message = MODULE_SHIPPING_UPSXML_RATES_TEXT_COMM_VERSION_ERROR;

return $message;

}

 

// Get response code. 1 = SUCCESS, 0 = FAIL

$responseStatusCode = $doc->getValueByPath('TimeInTransitResponse/Response/ResponseStatusCode');

 

if ($responseStatusCode != '1') {

$errorMsg = $doc->getValueByPath('TimeInTransitResponse/Response/Error/ErrorCode');

$errorMsg .= ": ";

$errorMsg .= $doc->getValueByPath('TimeInTransitResponse/Response/Error/ErrorDescription');

return $errorMsg;

}

 

$root = $doc->getRoot();

$serviceSummary = $root->getElementsByName("ServiceSummary");

for ($i = 0; $i < count($serviceSummary); $i++) {

$serviceCode = $serviceSummary[$i]->getValueByPath("Service/Code");

$timetransit = $serviceSummary[$i]->getValueByPath("EstimatedArrive/BusinessTransitDays");

if (!($serviceCode)) {

continue;

}

if ($serviceCode="GND"){

$gndtransit = $timetransit;

}

}

return $gndtransit;

}

 

The function works until I get to the line beginning $serviceSummary.

 

Any ideas?

 

Thanks,

 

Donna Gordon

UKGoods

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...