Actually, the changes to the original Canada Post PHP code (not the REST version) of the Sellonline code is fairly simple and works just fine.
This is from cp_al2_sm4_1_2_3_4_5
Go to catalog/includes/modules/canadapost.php
Around line 212 you will find:
PHP Code:
function _sendToHost($host,$port,$method,$path,$data,$useragent=0) {
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
if ($method == 'GET')
$path .= '?' . $data;
$buf = "";
// try to connect to Canada Post server, for 30 second (was 2 seconds, but IBM told me Canada Post can take up to 30 seconds to respond
$fp = @fsockopen($host, $port, $errno, $errstr, 30);
if ( $fp ) {
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
if ($useragent)
fputs($fp, "User-Agent: (your web site)\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
$buf .= fgets($fp,128);
fclose($fp);
} else {
$buf = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5 on your keyboard) to try again.</statusMessage></error></eparcel>';
}
if(!tep_not_null($buf)){
$buf = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5) to try again.</statusMessage></error></eparcel>';
}
return $buf;
}
replace all of that with:
PHP Code:
function _sendToHost($host,$port,$method,$path,$XML_data,$useragent=0) {
$CP_url = 'https://sellonline.canadapost.ca/sellonline/Rating';
$CP_Comm_context_options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $XML_data,
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
);
$CP_context = stream_context_create($CP_Comm_context_options);
$CP_response = file_get_contents($CP_url, false, $CP_context);
if (empty($CP_response)) {
$CP_response = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5 on your keyboard) to try again.</statusMessage></error></eparcel>';
}
if(!tep_not_null($CP_response)){
$CP_response = '<?xml version="1.0" ?><eparcel><error><statusMessage>Cannot reach Canada Post Server. You may refresh this page (Press F5) to try again.</statusMessage></error></eparcel>';
}
return $CP_response;
}
Then if it doesn't work, check that you have to turned allow_url_fopen = on (the '=' may not be needed) in your php.ini file for the server!
Doing this enabled me to still use sellonline - however they are not accepting new subcribers so this only works for established clients. The advantage of sellonline is the packing routine which allows you to measure up all your products (LxWxH & weight) and then let sellonline choose the best box from the list of boxes you provide to the system. Allows the shipping quotes to be fair to all.
Bookmarks