Jump to content
Sign in to follow this  
cmichalski

Shipping Module Creation Help

Recommended Posts

Hi all I am rather new to OsCommerce and I must say so far I am learning and having fun with it. I have come across one stumble. I am in need to ship very large Items and I use Conway exclusively on large items and UPS on the more normal stuff.. I really want and need this, looking for intersted parties to help develop this since I am not a PHP whiz at all. If your interested please contact me here on the forums or email me cmichalski@2dts.com This will be another great contribution for OsCommerce...

 

Can This Be Done ????

 

XML code from CONWAY..

 

<?php
/*
Con-way XML Sample Code for PHP - Rating interface
This code has been tested on PHP 4.3.XX and PHP 5.XX
-----------------
TODO:  
* replace the USERNAME and PASSWORD String values below 
with your Con-way username and password
* to get customer-specific discounts, replace CUSTNMBR String value
below with your Con-way customer number

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
-----------------
Send questions to Con-way XML Support at xmlsupport@Con-way.com
*/

$title = "Rating";
$requestType = "RateRequest";
$requestUrl = "https://www.Con-way.com/XMLj/X-Rate";

// replace the USERNAME and PASSWORD String values below with your Con-way username and password
$username = "USERNAME";
$password = "PASSWORD";
// to get a customer-specific discount, replace the CUSTNMBR string below with
// your Con-way customer number, then uncomment the <CustNmbr> line below.
$custNmbr = "CUSTNMBR";

$today = date("m/d/y");

// array of input data
$myInput = $_GET;
// If you don't pass data in as a GET variables, hard code them here:
if (! isset($myInput['origZip'])) {
$myInput['origZip'] = "19348";
}
if (! isset($myInput['destZip'])) {
$myInput['destZip'] = "97202";
}

// array of elements you want to query from the XML Response
$myElements = array('TotalCharge', 'Discount', 'TotalAccessorialCharges', 'NetCharge', 'TransitTime');

/*
Build XML Request
In actual use, you would probably populate the XML 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.
*/

$itemArray = array();	//Your commodity items, maximum of 4 - add as needed
$itemArray[] = array('class'=>'775', 'weight'=>'667');
$itemArray[] = array('class'=>'100', 'weight'=>'555');

$accArray = array();	// Your accessorial services - add as needed
$accArray[] = "SSC";
$accArray[] = "DNC";
$accArray[] = "GUR";

extract($myInput);
$xmlRequest="<RateRequest>" .

	"<OriginZip country=\"us\">$origZip</OriginZip>" .
	"<DestinationZip country=\"us\">$destZip</DestinationZip>";

// To get customer specific discount, uncomment this line:
// $xmlRequest .= "<CustNmbr shipcode=\"S\">$custNmbr</CustNmbr>";

$xmlRequest .= "<ChargeCode>P</ChargeCode>" .
	"<DiscountRate>100</DiscountRate>" .
	"<EffectiveDate>$today</EffectiveDate>";

foreach ($itemArray as $item) {	// Add commodity items to the XML Request
extract($item);
$xmlRequest .= "<Item>" .
		"<CmdtyClass>$class</CmdtyClass>" .
		"<Weight unit=\"lbs\">$weight</Weight>" .
		"</Item>";
}
foreach ($accArray as $acc) {	// Add accessorials to the XML Request
$xmlRequest .= "<Accessorial>$acc</Accessorial>";
}					  
$xmlRequest .= "</RateRequest>";

//Convert characters to proper format for HTTP POST
$xmlRequest = urlencode($xmlRequest);

// open synchronous connection to Con-way servlet and set options
$urlConn = curl_init ($requestUrl);
curl_setopt ($urlConn, CURLOPT_POST, 1);
curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, false);	// May be needed for SSL behind a firewall
curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt ($urlConn, CURLOPT_USERPWD, $username.":".$password);
curl_setopt ($urlConn, CURLOPT_POSTFIELDS, "$requestType=$xmlRequest");

// Get the XML Response
ob_start();	// prevent the buffer from being displayed
curl_exec($urlConn);
$xmlResponse = ob_get_contents();
ob_end_clean();

curl_close($urlConn);		// close the connection

// Parse the XML Response
$parser= xml_parser_create(); 
xml_parse_into_struct($parser,$xmlResponse,$xmlVals); 
xml_parser_free($parser);

// This function will return an array of the values of an element 
// given the $vals and $index arrays, and the element name
function getElementValue($xmlVals, $elName) { 
$elValue = null;
foreach ($xmlVals as $arrkey => $arrvalue) {
	foreach ($arrvalue as $key => $value) {
		if ($value==strtoupper($elName)){
			$elValue[] = $arrvalue['value'];
		}
	}
}
return $elValue;
}

// Build the HTML page
echo "
<html>
<head>
<title>Sample PHP for Con-way XML $title></title>
<script language=\"Javascript\" type=\"text/javascript\">
<!-- 
function erase(object) {
object.value=\"\";
}
// -->
</script>
</head>
<body text=\"SlateBlue\">
<center>
<B><font face=\"arial\" size=+1><I>Sample PHP Con-way XML $title</I></font></B>
</center>
<br>
<form action=\"". $_SERVER['PHP_SELF'] ."\" method=\"get\">
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
";
foreach ($myInput as $key => $value) {
if ($key != "Submit" && strlen($value))
echo "
  <tr>
	<td><b>" . strtoupper($key) . ":  </b></td>
	<td><input type=\"text\" name=\"$key\" value=\"$value\" 
			 onFocus=\"erase(this);\" onClick=\"erase(this);\"></td>
  </tr>
";
}
echo "
<tr><td> </td><td> </td></tr>
  <tr>
	<td> </td>
	<td><input type=\"submit\" name=\"Submit\" value=\"Process $title\"></td>
  </tr>
</table>
</form>
<hr>
";

// Extract your element values from the XML Response
$elCount = count(getElementValue($xmlVals, $myElements[0]));   // total occurrences

// The outer loop iterates the total number of occurrences of your first element
for ($i=0; $i < $elCount; $i++) {
// The inner loop iterates all of your elements, for each occurrence of the first
foreach ($myElements as $myEl) {
	$myVals = getElementValue($xmlVals, $myEl);
	echo "<b>Value of <$myEl> is: $myVals[$i]</b><BR>";;
}
echo '<br>';
}

echo "<b>Here is the dump of the XML output for $title:</b>" .
	"<code>$xmlResponse</code><br><br>" .
	"<b>And here it is displayed as a formatted array:</b><br>";
print_r($xmlVals);
echo 
	"</body>" .
	"</html>";

?>

Share this post


Link to post
Share on other sites

I took your advice and added the FedEx Freight v.6 contribution. So I could get to know how it was coded and all that. Well the code seems to work on the admin side and database side. Although when the data is submitted during check out it hangs the cart. No error nothing eventually I get CGI Time out error from my server. Anyone else have this problem ??? If some insight would be appreciated...

 

 

Thanks,

 

Craig

Share this post


Link to post
Share on other sites
Those kind of timeouts usually happen when the webserver cannot connect to the URL specified.

 

Check that you have the correct URL, etc.

 

Yeah this is crazy I can input all the data by hand into web browser and can see the return request of the xml parsing. But not sure what part of the module script it is hanging on. I have all errors reporting and warnings with nothing but the timeout of the CGI engine.

 

here is a link of the test site I use to make sure all contribs work before going head on my true website...

 

OSCOM TEST SITE

 

Does anyone know maybe little insert to the script that I can use to post to the screen and send the data is that possible..

 

nOOb I am !!

 

Craig - THANKS for you guys trying....

Share this post


Link to post
Share on other sites
Likely then it's a problem with CURL. I'm not familiar with the fed ex contributions, so I don't know if they try to use the command line or not. If you see it doing an exec(), then trying using the PHP CURL functions instead.

 

http://us3.php.net/curl

 

 

Great thanks for your help although this was not the case I am sure its a problem that could be added. Well looking into this all day can you believe the ANSWER is that I had a newer version of PHP Version 4.4.5RC2-dev now the working version is PHP Stable Version 4.4.5 fix for exactly CGI Expressions timeouthttp://snaps.php.net/win32/php4-win32-STABLE-latest.zip with all this said I will have to say I am at least more educated in these problem and not to blame the code for things that will not work.

 

Thanks to you all for helping through this gave me lots of help !!!

 

Craig

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×