Conway - CCX
dhs13 <[email protected]>
| Newsgroups | gmane.comp.web.oscommerce.features |
|---|---|
| Message-ID | <b0a5845bdf0b857c833156784a1c1d24@osCommerce-Forums> |
This message was sent from: Features
http://forums.oscommerce.com/viewtopic.php?p=193398#193398
----------------------------------------------------------------
Here is some PHP code for Conway-ccx. It was furnished by the carrier.
Here is some sample PHP code that will execute the XML based Con-Way rating application. Please contact us if you have any questions.
Thank you,
----------------------------------------------------------------------------
---------
<?php
// replace the "userId" & "passWd" String values with your Con-Way username and password $userId = "userId"; $passWd = "passWd";
/*
Build Rate Request
In actual use, you would probably populate the Rating Request
parameters (Weights, Classes, Zip Codes, etc.) from data submitted via an on-line order form or database. For this sample we will just hard code some dummy data. */
$rateRequest="<RateRequest>
<OriginZip country=\"us\">97006</OriginZip>
<DestinationZip country=\"us\">33179</DestinationZip>
<ChargeCode>P</ChargeCode>
<DiscountRate>100</DiscountRate>
<EffectiveDate>2/13/01</EffectiveDate>
<Item>
<CmdtyClass>775</CmdtyClass>
<Weight unit=\"lbs\">667</Weight>
</Item>
<Item>
<CmdtyClass>100</CmdtyClass>
<Weight unit=\"lbs\">555</Weight>
</Item>
<Accessorial>SSC</Accessorial>
<Accessorial>ZHM</Accessorial>
<Accessorial>DNC</Accessorial>
<Accessorial>GUR</Accessorial>
</RateRequest>";
//Convert characters to proper format for post
$rateRequest = urlencode($rateRequest);
// open synchronous connection to X-Rate servlet
// NOTE: you must have the cURL libraries installed with PHP on your
server--
// If you need them, see your System Administrator, who can get then at
// http://curl.haxx.se/download.html
$urlConn = curl_init ("http://www.con-way.com/XMLj/X-Rate");
curl_setopt ($urlConn, CURLOPT_POST, 1);
curl_setopt ($urlConn, CURLOPT_HTTPHEADER, "Content-type","application/x-www-form-urlencoded");
curl_setopt ($urlConn, CURLOPT_USERPWD, $userId.":".$passWd); curl_setopt ($urlConn, CURLOPT_POSTFIELDS, "RateRequest=".$rateRequest);
ob_start();
curl_exec($urlConn);
$rateQuote = ob_get_contents();
ob_end_clean();
/*
Parse the response
Here we simple redisplay the XML data, but in a real
world scenario you will parse the document to locate the data you wish to display
or save, such as the net charge, transit time, and disclaimer. */
$parser= xml_parser_create();
xml_parse_into_struct($parser,$rateQuote,$vals,$index);
xml_parser_free($parser);
// This function will return the value of an element given the $vals and $index arrays, // and the element name
function getElementValue($vals,$index,$elName) {
$elValue = null;
while ( list ( $keys, $values ) = each ($index)) {
if ($keys == strtoupper($elName)) {
list ( $key ) = $values;
while ( list ( $key1, $value1 ) = each
($vals[$key])) {
if ($key1 == "value") {
$elValue = $value1;
}
}
}
}
return $elValue;
}
// Use the above function to get the values you want, e.g. $totalCharge = getElementValue($vals,$index,"totalCharge");
echo
"<HTML>
<HEAD>
<TITLE>Sample PHP for Con-Way XML Rating</TITLE>
</HEAD>
<BODY>
<CENTER>
<B><FONT face=\"arial\" size=+1><I>Sample PHP Con-Way Rate Getter</I></FONT></B> </CENTER> <BR> <b>Here is the RateQuote XML output:</b> <BR> <xmp>".$rateQuote."</xmp> <B>Shipping Charges: </B>".$totalCharge ."</BODY> </HTML>"; ?>
----------------------------------------------------------------------------
----------------------------------------