Here is Canpar Shipping Module adapted to work with the MVS (Multi Vendor Shipping) Module:
/*
canpar.php,v 0.1 2006/07/22 10:52:11 hpdl Exp $ ORIGINAL CANPAR SCRIPT
Copyright (c) 2006 J. B. Wallace (jbwallace@shaw.ca) 2006.7.22
INTEGRATION WITH XML
Copyright (c) 2006 K. B. Gervais (kevinalwayswins@hotmail.com) 2006.8.25
Adaption copyright CyKron Interactive (www.cykron.com).
Canpar MVS (Multi Vendor Shipping) ADAPTATION
Copyright (c) 2007 S.A Aderogba (saderogba@gmail.com) 2007.12.13
Online Store Support (www.aderogba.com).
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
class canpar {
var $code, $title, $description, $icon, $enabled;
// class constructor
function canpar($method = '', $module = '', $vendors_id = '1') {
global $order; /*, $vendors_id;*/
$this->code = 'canpar';
$this->title = MODULE_SHIPPING_CANPAR_TEXT_TITLE;
$this->description = MODULE_SHIPPING_CANPAR_TEXT_DESCRIPTION;
//$this->mark_up = (int)constant('MODULE_SHIPPING_CANPAR_MARK_UP_'.$vendors_id);
//$this->mark_up = (int)$this->mark_up;
//$this->sort_order = MODULE_SHIPPING_CANPAR_SORT_ORDER;
$this->icon = DIR_WS_ICONS . 'canpar.gif';
//$this->tax_class = MODULE_SHIPPING_CANPAR_TAX_CLASS;
//$this->enabled = ((MODULE_SHIPPING_CANPAR_STATUS == 'True') ? true : false);
$this->delivery_country_id = $order->delivery['country']['id'];
$this->delivery_zone_id = $order->delivery['zone_id'];
$this->types = array(’GND’ => ‘Canada Ground’,
‘USA’ => ‘US Ground’,
‘SLET’ => ‘Select Letter’,
‘SPAK’ => ‘Select Pak’,
‘SPAR’ => ‘Select Parcel’);
}
///MVS Start
function sort_order($vendors_id=’1′) {
if (defined (@constant (’MODULE_SHIPPING_CANPAR_SORT_ORDER’ . $vendors_id))) {
$this->sort_order = @constant(’MODULE_SHIPPING_CANPAR_SORT_ORDER’ . $vendors_id);
} else {
$this->sort_order = ‘0′;
}
return $this->sort_order;
}
function tax_class($vendors_id=’1′) {
$this->tax_class = @constant(’MODULE_SHIPPING_CANPAR_TAX_CLASS_’ . $vendors_id);
return $this->tax_class;
}
function enabled($vendors_id=’1′) {
$this->enabled = false;
$status = @constant(’MODULE_SHIPPING_CANPAR_STATUS_’ . $vendors_id);
if (isset ($status) && $status != ”) {
$this->enabled = (($status == ‘True’) ? true : false);
}
return $this->enabled;
}
function zones($vendors_id=’1′) {
if ( ($this->enabled == true) && ((int)constant(’MODULE_SHIPPING_CANPAR_ZONE_’ . $vendors_id) > 0) ) {
$check_flag = false;
$check_query = tep_db_query(”select zone_id from ” . TABLE_ZONES_TO_GEO_ZONES . ” where geo_zone_id = ‘” . (int)constant(’MODULE_SHIPPING_CANPAR_ZONE_’ . $vendors_id) . “‘ and zone_country_id = ‘” . $order->delivery['country']['id'] . “‘ order by zone_id”);
while ($check = tep_db_fetch_array($check_query)) {
if ($check['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
} //if
}//while
if ($check_flag == false) {
$this->enabled = false;
}//if
}//if
return $this->enabled;
}
///
// class methods
function quote($method = ”, $module=”, $vendors_id=’1′) {
global $order, $shipping_weight,$shipping_num_boxes, $cart;
$srcFSA = substr(strtoupper(SHIPPING_ORIGIN_ZIP), 0, 3);
$desFSA = substr(strtoupper($order->delivery['postcode']), 0, 3);
$srcFSA1stLetter = substr(strtoupper(SHIPPING_ORIGIN_ZIP), 0, 1);
$desFSA1stLetter = substr(strtoupper($order->delivery['postcode']), 0, 1);
//$PkgWT = $shipping_weight;
// start of modification to get weight for this vendor only instead of using total cart weight
$PkgWT=0;
$products_array = $cart->get_products();
//print_r($products_array);
$xc_count=0;
for($ii=0; $ii
{
if($products_array[$ii]['vendors_id'] == $vendors_id)
{
$PkgWT = $PkgWT + $products_array[$ii]['weight']*$products_array[$ii]['quantity'];
$xc_count = $xc_count + 1;
}
}
// end
/*
//Connect to CanPar here to get quote, and parse XML.
$request = join(’&’, array(’service=1′,
‘quantity=’ . $shipping_num_boxes,
‘unit=L’,
‘origin=’ . $srcFSA,
‘dest=’ . $desFSA,
‘cod=0′,
‘weight=’ . intval($shipping_weight),
‘put=0′,
‘xc=0′,
‘dec=0′));
$http = new httpClient();
if ($http->Connect(’www.canpar.com’, 80)) {
$http->addHeader(’Host’, ‘www.canpar.com’);
$http->addHeader(’User-Agent’, ‘osCommerce’);
$http->addHeader(’Connection’, ‘Close’);
if ($http->Get(’/CanparRateXML/BaseRateXML.jsp?’ . $request)) $body = $http->getBody();
$http->Disconnect();
} else {
return ‘error’;
}
$body_array = explode(”", $body);
$ShippingCost = $body_array[1];
$ShippingCost = ereg_replace(”, ”, $ShippingCost);
*/
$this->quotes = array(’id’ => $this->code,
‘module’ => $this->title . ‘ (’ . $xc_count . ‘ x ‘ . $PkgWT . ‘lbs)’);
//MVS ADD
$vendors_data_query = tep_db_query(”select handling_charge, handling_per_box, vendor_country
from ” . TABLE_VENDORS . ”
where vendors_id = ‘” . (int)$vendors_id . “‘”
);
$vendors_data = tep_db_fetch_array($vendors_data_query);
$country_name = tep_get_countries($vendors_data['vendor_country'], true);
$handling_charge = $vendors_data['handling_charge'];
$handling_per_box = $vendors_data['handling_per_box'];
if ($handling_charge > $handling_per_box*$xc_count) {
$handling = $handling_charge;
} else {
$handling = $handling_per_box*$xc_count;
}
//MVS END
// Begin Connect Method Patch
$methods = array();
$allowed_methods = explode(”, “, @constant (’MODULE_SHIPPING_CANPAR_TYPES_’ . $vendors_id));
$temp_arr =array();
if($order->delivery['country']['iso_code_3'] == ‘USA’) //if delivery is USA, remove all non-USA methods
{
for($ii=0; $ii
{
if($allowed_methods[$ii] != ‘USA’)continue;
else $temp_arr[] = $allowed_methods[$ii];
}
}
else
{
$temp_arr =array();
if($order->delivery['country']['iso_code_3'] != ‘USA’)
{
for($ii=0; $ii
{
if($allowed_methods[$ii] == ‘USA’)continue;
else $temp_arr[] = $allowed_methods[$ii];
}
}
}
unset($allowed_methods);
$allowed_methods=$temp_arr;
$mark_up = (int)constant(’MODULE_SHIPPING_CANPAR_MARK_UP_’.$vendors_id);
for($ii=0; $ii
if($allowed_methods[$ii]==’GND’)$sel_ser=’1′;
if($allowed_methods[$ii]==’USA’)$sel_ser=’2′;
if($allowed_methods[$ii]==’SLET’)$sel_ser=’3′;
if($allowed_methods[$ii]==’SPAK’)$sel_ser=’4′;
if($allowed_methods[$ii]==’SPAR’)$sel_ser=’5′;
$request = join(’&’, array(’service=’.$sel_ser,
‘quantity=’ . $xc_count,
‘unit=L’,
‘origin=’ . $srcFSA,
‘dest=’ . $desFSA,
‘cod=0′,
‘weight=’ . intval($PkgWT),
‘put=0′,
‘xc=0′,
‘dec=0′));
$body = file_get_contents(’http://www.canpar.com/CanparRateXML/BaseRateXML.jsp?’ . $request);
$body_array = explode(”", $body);
$ShippingCost = $body_array[1];
$ShippingCost = ereg_replace(”, ”, $ShippingCost);
$methods[] = array(’id’ => $allowed_methods[$ii],
‘title’ => $this->types[$allowed_methods[$ii]],
‘cost’ => ($ShippingCost * $shipping_num_boxes) + $handling + $mark_up);
}
//print_r($methods);
// End Connect Method Patch
if (strlen($ErrMsg) == 0) {
//$this->quotes = array(’id’ => $this->code,
// ‘module’ => MODULE_SHIPPING_CANPAR_TEXT_TITLE,
// ‘methods’ => array(array(’id’ => $this->code,
// ‘title’ => MODULE_SHIPPING_CANPAR_TEXT_WAY,
// ‘cost’ => $ShippingCost + $handling + $this->mark_up)));
$this->quotes['methods'] = $methods;
} else {
$this->quotes = array(’module’ => $this->title,
‘error’ => $ErrMsg);
}
if ($this->tax_class($vendors_id) > 0) {
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class($vendors_id), $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (tep_not_null($this->icon)) $this->quotes['icon'] = ‘
‘ . tep_image($this->icon, $this->title);
return $this->quotes;
}
function check($vendors_id=’1′) {
if (!isset($this->_check)) {
$check_query = tep_db_query(”select configuration_value from ” . TABLE_VENDOR_CONFIGURATION . ” where vendors_id = ‘”. $vendors_id .”‘ and configuration_key = ‘MODULE_SHIPPING_CANPAR_STATUS_” . $vendors_id . “‘”);
$this->_check = tep_db_num_rows($check_query);
}
return $this->_check;
}
function install($vendors_id=’1′) {
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values (’Enable CANPAR Shipping’, ‘MODULE_SHIPPING_CANPAR_STATUS_” . $vendors_id . “‘, ‘True’, ‘Do you want to offer CANPAR rate shipping?’, ‘6′, ‘0′, ‘tep_cfg_select_option(array(\’True\’, \’False\’), ‘, now(), ‘” . $vendors_id . “‘)”);
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values (’Tax Class’, ‘MODULE_SHIPPING_CANPAR_TAX_CLASS_” . $vendors_id . “‘, ‘0′, ‘Use the following tax class on the shipping fee.’, ‘6′, ‘0′, ‘tep_get_tax_class_title’, ‘tep_cfg_pull_down_tax_classes(’, now(), ‘” . $vendors_id . “‘)”);
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values (’Mark Up’, ‘MODULE_SHIPPING_CANPAR_MARK_UP_” . $vendors_id . “‘, ‘1′, ‘Use the following mark-up on the shipping list fees.’, ‘6′, ‘0′, now(), ‘” . $vendors_id . “‘)”);
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values (’Sort Order’, ‘MODULE_SHIPPING_CANPAR_SORT_ORDER_” . $vendors_id . “‘, ‘0′, ‘Sort order of display.’, ‘6′, ‘0′, now(), ‘” . $vendors_id . “‘)”);
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values (’Shipping Zone’, ‘MODULE_SHIPPING_CANPAR_ZONE_” . $vendors_id . “‘, ‘0′, ‘If a zone is selected, only enable this shipping method for that zone.’, ‘6′, ‘0′, ‘tep_get_zone_class_title’, ‘tep_cfg_pull_down_zone_classes(’, now(), ‘” . $vendors_id . “‘)”);
tep_db_query(”insert into ” . TABLE_VENDOR_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values (’Shipping Methods’, ‘MODULE_SHIPPING_CANPAR_TYPES_” . $vendors_id . “‘, ‘GND, USA, SLET, SPAK, SPAR’, ‘Select the CANPAR services to be offered.’, ‘6′, ‘0′, ‘tep_cfg_select_multioption(array(\’GND\’,\’USA\’, \’SLET\’, \’SPAK\’, \’SPAR\’), ‘, now(), ‘” . $vendors_id . “‘)”);
}
function remove($vendors_id=’1′) {
tep_db_query(”delete from ” . TABLE_VENDOR_CONFIGURATION . ” where vendors_id = ‘”.$vendors_id.”‘ and configuration_key in (’” . implode(”‘, ‘”, $this->keys($vendors_id)) . “‘)”);
}
function keys($vendors_id=’1′) {
return array(’MODULE_SHIPPING_CANPAR_STATUS_’.$vendors_id, ‘MODULE_SHIPPING_CANPAR_TAX_CLASS_’.$vendors_id, ‘MODULE_SHIPPING_CANPAR_MARK_UP_’.$vendors_id, ‘MODULE_SHIPPING_CANPAR_SORT_ORDER_’.$vendors_id, ‘MODULE_SHIPPING_CANPAR_ZONE_’ . $vendors_id, ‘MODULE_SHIPPING_CANPAR_TYPES_’ . $vendors_id);
}
}
?>
Enjoy! Contact me if you have problem using it.
Recent Comments