You will need PHP 5. and Curl support,
to use this FedEX XML rate request PHP script.
If your Host does not support these,
I use Camelot Hosting, they are Zen Cart Hosts.
http://www.camelot-hosting.com/hosting/
The Con Way XML Rate Quote Requese can be found at,
FORUM PAGE LINK
http://www.zen-cart.com/forum/showth...reate+a+module
These 2 XML scripts must be custom addaped to your requirments.
-----
includes/languages/english/modules/shipping/fedex.php
----
<?php
/*
Released under the GNU General Public License
*/
define('MODULE_SHIPPING_FXFREIGHT_TEXT_TITLE', 'FedEx Freight');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_DESCRIPTION', 'FedEx Freight transports items too large for their regular service.');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_WAY', 'FedEx Freight');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_BAD_COUNTRY', 'FedEx Freight is only available to customer in the United States and Canada.');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_BAD_RESPONSE', 'FedEx Freight returned an error or invalid response.');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_DESCRIPTION', 'We\'re sorry, but an error occured while calculating the FedEx Freight shipping prices.');
define('MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_SHIPPING_WITHIN_CA', 'We\'re sorry, but FedEx Freight\'s estimator does not currently support estimates for shipping from one Canadian address to another.');
?>
--------------------------------------------------------------------------------
includes/modules/shipping/fedex.php
-
<?php
/*
Released under the GNU General Public License
*/
class fxfreight extends base {
var $code, $title, $description, $icon, $enabled;
// class constructor
function fxfreight() {
global $total_weight, $order, $db, $template;
$this->code = 'fxfreight';
$this->title = MODULE_SHIPPING_FXFREIGHT_TEXT_TITLE;
$this->description = MODULE_SHIPPING_FXFREIGHT_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_FXFREIGHT_SORT_ORDER;
$this->icon = DIR_WS_IMAGES . 'fedex-images/FREIGHT.gif';
$this->tax_class = MODULE_SHIPPING_FXFREIGHT_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_FXFREIGHT_STATUS == 'True') ? true : false);
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FXFREIGHT_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FXFREIGHT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
if($this->enabled == true && $order->delivery['country']['iso_code_2']!='US' && $order->delivery['country']['iso_code_2']!='CA') {
$this->enabled = false;
}
$this->shipping_weight = 0;
$this->shipping_num_boxes = 1;
if ($this->enabled == true && (is_numeric($total_weight) || $_SESSION['cart']->attributes_1216ft()==true) ) {
$this->shipping_weight = $total_weight;
if($this->shipping_weight <= 150 && $_SESSION['cart']->attributes_1216ft()==false) {
$this->enabled = false;
return false;
}
}
}
// class methods
function quote($method = '') {
global $total_weight, $zc_large_percent, $zc_large_weight, $shipping_weight, $shipping_num_boxes, $cart, $order;
$this->shipping_weight = $total_weight;// + ($total_weight*($zc_large_percent/100)) + $zc_large_weight;
if($this->shipping_weight <= 150 && $_SESSION['cart']->attributes_1216ft()==false) {
$this->enabled = false;
return false;
} else {
$error_msg = '';
//First, we get the customer's zipcode and country in the right format.
$dest_country = $order->delivery['country']['iso_code_2'];
if ($dest_country == 'US') {
$dest_zip = preg_replace('/[^0-9]/i', '', strtoupper($order->delivery['postcode']));
$dest_zip = substr($dest_zip, 0, 5);
} elseif ($dest_country == 'CA') {
$dest_zip = preg_replace('/[^0-9A-Z]/i', '', strtoupper($order->delivery['postcode']));
$dest_zip = substr($dest_zip, 0, 6);
} else {
$error_msg = '<br>' . MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_BAD_COUNTRY;
}
//Format the shipping zip code as well
if (MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY == 'US') {
$ship_zip = preg_replace('/[^0-9]/i', '', MODULE_SHIPPING_FXFREIGHT_SHIP_ZIP);
$ship_zip = substr($ship_zip, 0, 5);
} elseif (MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY == 'CA') {
$ship_zip = preg_replace('/[^0-9A-Z]/i', '', strtoupper(MODULE_SHIPPING_FXFREIGHT_SHIP_ZIP));
$ship_zip = substr($ship_zip, 0, 6);
}
if (!zen_not_null($error_msg)) {
$base_URL = 'http://www.fedexfreight.fedex.com/XMLRating.jsp?';
$base_URL .= 'as_shipterms=' . MODULE_SHIPPING_FXFREIGHT_SHIP_TERMS;
$base_URL .= '&as_shzip=' . $ship_zip;
$base_URL .= '&as_shcntry=' . MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY;
$base_URL .= '&as_cnzip=' . $dest_zip;
$base_URL .= '&as_cncntry=' . $dest_country;
$base_URL .= '&as_class1=050';
$base_URL .= '&as_weight1='.ceil($this->shipping_weight);//urlencode(number_format($this->shipping_weight, 1, '.', ''));
$base_URL .= '&as_pcs1='.$this->shipping_num_boxes;
$base_URL .= '&as_iamthe=shipper';
if (MODULE_SHIPPING_FXFREIGHT_DECLARE_VALUE == 'True') {
$base_URL .= '&as_decvalue=' . ceil($order->info['subtotal']);//urlencode(number_format($order->info['subtotal'], 2, '.', ''));
}
if (MODULE_SHIPPING_FXFREIGHT_RES_DELIVERY == 'True' && !zen_not_null($order->delivery['company'])) {
$base_URL .= '&as_residentialdelivery=Y';
}
if (MODULE_SHIPPING_FXFREIGHT_INS_PICKUP != 'None') {
$base_URL .= '&as_insidepickup=' . MODULE_SHIPPING_FXFREIGHT_INS_PICKUP;
}
if (MODULE_SHIPPING_FXFREIGHT_INS_DELIVERY != 'None') {
$base_URL .= '&as_insidedelivery='.MODULE_SHIPPING_FXFREIGHT_INS_DELIVERY;
}
$base_URL .= '&as_singleshipment=Y';
$base_URL .= '&as_callbefore='.MODULE_SHIPPING_FXFREIGHT_CBD;
$base_URL .= '&as_liftgate='.MODULE_SHIPPING_FXFREIGHT_LIFT_GATE;
$account_Params = '';
if (trim(MODULE_SHIPPING_FXFREIGHT_ACCT_NUM) != '') {
$account_Params .= '&as_acctnbr=' . MODULE_SHIPPING_FXFREIGHT_ACCT_NUM;
}
//http://www.fedexfreight.fedex.com/XMLRating.jsp?as_shipterms=prepaid&as_shzip=72601&as_shcntry=US&as_cnzip=77306&a s_cncntry=US&as_class1=050&as_weight1=400&as_pcs1=1&as_insidedelivery=IDP&as_cal lbefore=Y&as_iamthe=shipper&as_singleshipment=Y
$total_shipping_price = 0;
$ship_price = $this->getFXFQuote($base_URL.$account_Params);
if (!$ship_price) {
$ship_price = $this->getFXFQuote($base_URL);
if (!$ship_price) {
//Currently, shipping within CA is not supported
if (MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY == 'CA' && $dest_country == 'CA') {
$error_msg .= '<br>' . MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_SHIPPING_WITHIN_CA . '<br>';
} else {
$error_msg .= '<br>' . MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_BAD_RESPONSE;// . '<br>' . $base_URL;
}
} else {
$handling_fee = MODULE_SHIPPING_FXFREIGHT_HANDLING;
if(!zen_not_null($handling_fee)) {
$handling_fee = 0;
} elseif(substr($handling_fee, -1) == '%') {
$handling_fee = ($handling_fee / 100) * $ship_price;
} elseif($handling_fee > 0 && $handling_fee < 1) {
$ship_price = $ship_price/$handling_fee;
$handling_fee = 0;
}
$total_shipping_price = $ship_price + $handling_fee;
}
} else {
$handling_fee = MODULE_SHIPPING_FXFREIGHT_HANDLING;
if(!zen_not_null($handling_fee)) {
$handling_fee = 0;
} elseif(substr($handling_fee, -1) == '%') {
$handling_fee = ($handling_fee / 100) * $ship_price;
} elseif($handling_fee > 0 && $handling_fee < 1) {
$ship_price = $ship_price/$handling_fee;
$handling_fee = 0;
}
$total_shipping_price = $ship_price + $handling_fee;
}
}//if (!zen_not_null($error_msg)) {
if (!zen_not_null($error_msg)) {
$items_1216ft_fee = MODULE_SHIPPING_FXFREIGHT_ITEMS1216FT_FEE;
$items_1216ft_fee = trim($items_1216ft_fee);
if(is_numeric($items_1216ft_fee)) {
if($_SESSION['cart']->attributes_1216ft()==true) $total_shipping_price = $total_shipping_price + MODULE_SHIPPING_FXFREIGHT_ITEMS1216FT_FEE;
}
$this->quotes = array('id' => $this->code,
'module' => '',//MODULE_SHIPPING_FXFREIGHT_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_FXFREIGHT_TEXT_WAY,
'cost' => $total_shipping_price)));
if ($this->tax_class > 0) {
$this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
} else {
$this->quotes = array('module' => $this->title,
'error' => MODULE_SHIPPING_FXFREIGHT_TEXT_ERROR_DESCRIPTION . $error_msg);
}
return $this->quotes;
}
}
function getFXFQuote($url) {
$isError = false;
$connectMethod = false;
if (($fp = @fopen($url, "r"))) {
$connectMethod = 'fopen';
$data = fread($fp, 4096);
} elseif (function_exists('curl_init')) {
$connectMethod = 'curl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
}
if ($connectMethod) {
if (strpos($fp, 'RATINGERROR') === true || strpos($data, '<NetFreightCharges>') === false) {
return false;
} else {
$start_pos = strpos($data, '<NetFreightCharges>') + 20;
$string_len = strpos($data, '</NetFreightCharges>') - $start_pos;
$shipping_price = str_replace(',', '', substr($data, $start_pos, $string_len));
if (is_numeric($shipping_price)) {
return $shipping_price;
} else {
return false;
}
}
} else {
return false;
}
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FXFREIGHT_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable FedEx Freight Shipping', 'MODULE_SHIPPING_FXFREIGHT_STATUS', 'True', 'Do you want to offer FedEx Freight shipping?', '6', '10', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Terms', 'MODULE_SHIPPING_FXFREIGHT_SHIP_TERMS', 'prepaid', 'Will these shipments be prepaid or collect? (This is here for future dev. No collect support right now)', '6', '20', 'zen_cfg_select_option(array(\'prepaid\', \'collect\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipper\'s Zip Code', 'MODULE_SHIPPING_FXFREIGHT_SHIP_ZIP', 'zIP cODE', 'Enter the zip code of where these shipments will be sent from. (Required)', '6', '30', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipper\'s Country', 'MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY', 'US', 'Select the country where these shipments will be sent from.', '6', '40', 'zen_cfg_select_option(array(\'US\', \'CA\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Account Number', 'MODULE_SHIPPING_FXFREIGHT_ACCT_NUM', 'aCCOUNT nUMBER', 'If you have a FedEx Freight account number, enter it here. (Optional)', '6', '50', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Declare Shipment Value?', 'MODULE_SHIPPING_FXFREIGHT_DECLARE_VALUE', 'False', 'Do you want to declare the value of the shipments? (the order total will be used)', '6', '60', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Inside Pickup', 'MODULE_SHIPPING_FXFREIGHT_INS_PICKUP', 'None', 'Indicates if this is an inside pickup and the terms (prepaid or collect).', '6', '70', 'zen_cfg_select_option(array(\'None\', \'IPP\', \'IPC\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Inside Delivery', 'MODULE_SHIPPING_FXFREIGHT_INS_DELIVERY', 'None', 'Indicates if this is an inside delivery and the terms (prepaid or collect).', '6', '72', 'zen_cfg_select_option(array(\'None\', \'IDP\', \'IDC\'), ', now())");
//$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Residential Pickup', 'MODULE_SHIPPING_FXFREIGHT_RES_PICKUP', 'N', 'Will FedEx be picking up the shipments at a residence?', '6', '74', 'zen_cfg_select_option(array(\'Y\', \'N\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Residential Delivery', 'MODULE_SHIPPING_FXFREIGHT_RES_DELIVERY', 'False', 'Enable residential delivery if delivery address has no company name?', '6', '77', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Call Before Delivery', 'MODULE_SHIPPING_FXFREIGHT_CBD', 'N', 'Indicates if notification prior to delivery is required.', '6', '80', 'zen_cfg_select_option(array(\'Y\', \'N\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Lift Gate', 'MODULE_SHIPPING_FXFREIGHT_LIFT_GATE', 'N', 'Will FedEx need a lift gate to pick up the shipments?', '6', '85', 'zen_cfg_select_option(array(\'Y\', \'N\'), ', now())");
//$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Error Logs', 'MODULE_SHIPPING_FXFREIGHT_ERROR_ACTION', 'Email', 'If FedEx kicks back an error, how do you want to display it? (Email to store owner, display to customer, or none)', '6', '90', 'zen_cfg_select_option(array(\'Email\', \'Display\', \'None\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_FXFREIGHT_HANDLING', '.72', 'Handling fee for this shipping method.', '6', '100', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Items 12/16 FT Fee', 'MODULE_SHIPPING_FXFREIGHT_ITEMS1216FT_FEE', '70.00', 'Handling fee on items 12/16 FT lengths for this shipping method.', '6', '105', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FXFREIGHT_TAX_CLASS', '1', 'Use the following tax class on the shipping fee.', '6', '110', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FXFREIGHT_ZONE', '6', 'If a zone is selected, only enable this shipping method for that zone.', '6', '120', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_FXFREIGHT_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '130', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_SHIPPING_FXFREIGHT_STATUS', 'MODULE_SHIPPING_FXFREIGHT_SHIP_TERMS', 'MODULE_SHIPPING_FXFREIGHT_SHIP_ZIP', 'MODULE_SHIPPING_FXFREIGHT_SHIP_COUNTRY', 'MODULE_SHIPPING_FXFREIGHT_ACCT_NUM', 'MODULE_SHIPPING_FXFREIGHT_INS_PICKUP', 'MODULE_SHIPPING_FXFREIGHT_INS_DELIVERY', 'MODULE_SHIPPING_FXFREIGHT_CBD', 'MODULE_SHIPPING_FXFREIGHT_DECLARE_VALUE', 'MODULE_SHIPPING_FXFREIGHT_RES_DELIVERY', 'MODULE_SHIPPING_FXFREIGHT_LIFT_GATE', 'MODULE_SHIPPING_FXFREIGHT_HANDLING', 'MODULE_SHIPPING_FXFREIGHT_ITEMS1216FT_FEE', 'MODULE_SHIPPING_FXFREIGHT_TAX_CLASS', 'MODULE_SHIPPING_FXFREIGHT_ZONE', 'MODULE_SHIPPING_FXFREIGHT_SORT_ORDER');
}
}
?>
Bookmarks