Code:
case '1':
default:
$shipping_form .= 'Commercial (no loading dock)';
break;
}
}
if (count($errors) < 1) {
$shipping_options = array();
$shipping_options[] = array('id' => 'CHEAPEST',
'title' => MODULE_SHIPPING_FREIGHTQUOTE_TEXT_WAY . $total_shipping_price['shipment_id'] . ($excluded_items > 0 ? MODULE_SHIPPING_FREIGHTQUOTE_TEXT_EXCLUDED . $excluded_items : '') . $shipping_form,
'cost' => $total_shipping_price['rate'],
'tfrc_quote_id' => $total_shipping_price['shipment_id']);
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_FREIGHTQUOTE_TEXT_TITLE,
'methods' => $shipping_options);
if (isset($_REQUEST['freightquote_delivery_location'])) {
$_SESSION['shipping'] = array(
'id' => $this->code . '_CHEAPEST',
'title' => $this->quotes['methods'][0]['title'],
'cost' => $this->quotes['methods'][0]['title'],
'module' => $this->code
);
}
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 {
$error_message = '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>';
$this->quotes = array('module' => $this->title . $shipping_form,
'error' => $error_message);
}
return $this->quotes;
}
function query_rates($request_xml) {
//Make sure cURL exists
if (!function_exists('curl_init')) {
return array('error' => MODULE_SHIPPING_FREIGHTQUOTE_TEXT_ERROR_CURL);
}
//URL to send requests to
$service_url = 'https://b2b.Freightquote.com/WebService/QuoteService.asmx';
//XML template file used for request
$query_xml = $xml = $this->array_to_xml($request_xml);
//Make sure the XML file exists
$this->request = $query_xml;
//Initialize curl
$ch = curl_init();
$headers = array(
'Content-Type: text/xml; charset=utf-8',
'Content-Length: ' . strlen($this->request),
'SOAPAction: "http://tempuri.org/GetRatingEngineQuote"'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->request);
$this->response = curl_exec($ch);
if (curl_errno($ch) == 0) {
curl_close($ch);
//Simple check to make sure that this is a valid XML response
if (strpos(strtolower($this->response), 'soap:envelope') === false) {
return array('error' => MODULE_SHIPPING_FREIGHTQUOTE_TEXT_ERROR_DESCRIPTION);
}
if ($this->response) {
//Convert the XML into an easy-to-use associative array
$this->response = $this->parse_xml($this->response);
}
return $this->response;
} else {
//Collect the error returned
$curl_errors = curl_error($ch) . ' (Error No. ' . curl_errno($ch) . ')';
curl_close($ch);
return array('error' => $curl_errors);
}
}
function array_to_xml($array, $wrapper = true) {
$xml = '';
$first_key = false;
if ($wrapper) {
$xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n" .
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' . "\n" .
'<soap:Body>' . "\n";
$first_key = true;
}
foreach ($array as $key => $value) {
$position = 0;
if (is_array($value)) {
$is_value_assoc = $this->is_assoc($value);
$xml .= "<$key" . ($first_key ? ' xmlns="http://tempuri.org/"' : '') . ">\n";
$first_key = false;
foreach ($value as $key2 => $value2) {
if (is_array($value2)) {
if ($is_value_assoc) {
$xml .= "<$key2>\n" . $this->array_to_xml($value2, false) . "</$key2>\n";
} elseif (is_array($value2)) {
$xml .= $this->array_to_xml($value2, false);
$position++;
if ($position < count($value) && count($value) > 1) $xml .= "</$key>\n<$key>\n";
}
} else {
$xml .= "<$key2>" . $this->xml_safe($value2) . "</$key2>\n";
}
}
$xml .= "</$key>\n";
} else {
$xml .= "<$key>" . $this->xml_safe($value) . "</$key>\n";
}
}
if ($wrapper) {
$xml .= '</soap:Body>' . "\n" .
'</soap:Envelope>';
}
return $xml;
}
function is_assoc($array) {
return (is_array($array) && 0 !== count(array_diff_key($array, array_keys(array_keys($array)))));
}
function parse_xml($text) {
$reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
preg_match_all($reg_exp, $text, $match);
foreach ($match[1] as $key=>$val) {
if ( preg_match($reg_exp, $match[2][$key]) ) {
$array[$val][] = $this->parse_xml($match[2][$key]);
} else {
$array[$val] = $match[2][$key];
}
}
return $array;
}
function xml_safe($str) {
//The 5 evil characters in XML
$str = str_replace('<', '<', $str);
$str = str_replace('>', '>', $str);
$str = str_replace('&', '&', $str);
$str = str_replace("'", ''', $str);
$str = str_replace('"', '"', $str);
return $str;
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute(
"SELECT configuration_value " .
"FROM " . TABLE_CONFIGURATION . " " .
"WHERE configuration_key = 'MODULE_SHIPPING_FREIGHTQUOTE_STATUS' " .
"LIMIT 1"
);
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function next_business_day() {
$next_date = date("U")+86400;
$workday = date("w", $next_date);
if ($workday > 0 && $workday < 6) {
return date(DATE_ATOM, $next_date);
} else {
while ($workday < 1 || $workday > 5) {
$next_date += 86400;
$workday = date("w", $next_date);
if ($workday > 0 && $workday < 6) {
return date(DATE_ATOM, $next_date);
}
}
}
}
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 Freightquote.com Shipping Module', 'MODULE_SHIPPING_FREIGHTQUOTE_STATUS', 'True', 'Do you want to offer Freightquote.com shipping?', '6', '0', '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 ('Enable Freightquote.com Debug Mode', 'MODULE_SHIPPING_FREIGHTQUOTE_DEBUG', 'False', 'Enable debug mode? This will dump the data string to the user\'s screen when an error occurs. Should not be turned on unless there are problems.', '6', '0', '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, date_added) values ('Username', 'MODULE_SHIPPING_FREIGHTQUOTE_USERNAME', '[email protected]', 'Enter your Freightquote.com Username', '6', '1', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Password', 'MODULE_SHIPPING_FREIGHTQUOTE_PASSWORD', 'XML', 'Enter your Freightquote.com Password', '6', '1', 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 ('Service Type', 'MODULE_SHIPPING_FREIGHTQUOTE_SERVICE_TYPE', 'LTL', 'What service type do you want to use?', '6', '0', 'zen_cfg_select_option(array(\'LTL\', \'Truckload\', \'Europe\', \'Groupage\', \'Haulage\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Origin: Zip Code', 'MODULE_SHIPPING_FREIGHTQUOTE_SHIP_ZIP', '', 'What zip code will you be shipping from?', '6', '1', 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 Origin: Country', 'MODULE_SHIPPING_FREIGHTQUOTE_SHIP_COUNTRY', '223', 'What country will you be shipping from?', '6', '1', 'zen_get_country_name', 'zen_cfg_pull_down_country_list(', 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 Origin: Loading Dock', 'MODULE_SHIPPING_FREIGHTQUOTE_LOADING_DOCK', 'True', 'Does the shipping location have a loading dock?', '6', '0', '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 Origin: Residence', 'MODULE_SHIPPING_FREIGHTQUOTE_RESIDENCE', 'True', 'Is the shipping location a residence?', '6', '0', '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 Origin: Construction Site', 'MODULE_SHIPPING_FREIGHTQUOTE_CONSTRUCTION_SITE', 'True', 'Is the shipping location a construction site?', '6', '0', '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 ('Blind Ship', 'MODULE_SHIPPING_FREIGHTQUOTE_BLIND', 'True', 'Blind shipments are used to keep the originating location and receiving destination unaware of each other.', '6', '0', '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, date_added) values ('Price Modifier', 'MODULE_SHIPPING_FREIGHTQUOTE_PRICE_MODIFIER', '1', 'This number will be multiplied by the total shipping rate. If you\'d like to increase or decrease the price returned, modify this field. e.g. For a 10% price increase, enter 1.1', '6', '1', 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_FREIGHTQUOTE_HANDLING', '0', 'Handling fee for this shipping method (peritem).', '6', '0', 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_FREIGHTQUOTE_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', '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_FREIGHTQUOTE_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', '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_FREIGHTQUOTE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', 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 ('Default delivery location', 'MODULE_SHIPPING_FREIGHTQUOTE_DELIVERY_LOCATION', 'Commercial (no loading dock)', 'Default delivery location type', '6', '0', 'zen_cfg_select_option(array(\'Residence\', \'Commercial (no loading dock)\', \'Commercial (with loading dock)\', \'Construction Site\'), ', now())");
$col_query = $db->Execute("SHOW COLUMNS FROM " . TABLE_PRODUCTS);
$found = array(
'products_freightquote_enable' => array('type' => "CHAR( 1 ) DEFAULT '0' NOT NULL"),
'products_freightquote_class' => array('type' => "VARCHAR( 6 ) DEFAULT '50' NOT NULL"),
'products_freightquote_length' => array('type' => "INT DEFAULT '0' NOT NULL"),
'products_freightquote_width' => array('type' => "INT DEFAULT '0' NOT NULL"),
'products_freightquote_height' => array('type' => "INT DEFAULT '0' NOT NULL"),
'products_freightquote_nmfc' => array('type' => "VARCHAR(32) NULL"),
'products_freightquote_hzmt' => array('type' => "VARCHAR(5) DEFAULT 'false' NOT NULL"),
'products_freightquote_package_type' => array('type' => "VARCHAR(32) DEFAULT 'Boxes' NOT NULL"),
'products_freightquote_commodity_type' => array('type' => "VARCHAR(32) DEFAULT 'GeneralMerchandise' NOT NULL"),
'products_freightquote_content_type' => array('type' => "VARCHAR(32) DEFAULT 'NewCommercialGoods' NOT NULL")
);
while (!$col_query->EOF) {
$columns[] = $col_query->fields['Field'];
$col_query->MoveNext();
}
foreach ($found as $col => $info) {
if (!in_array($col, $columns)) {
$db->Execute("ALTER TABLE " . TABLE_PRODUCTS . " ADD `" . $col . "` " . $info['type']);
}
}
}
function remove() {
global $db;
$db->Execute("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key IN ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array(
'MODULE_SHIPPING_FREIGHTQUOTE_STATUS',
'MODULE_SHIPPING_FREIGHTQUOTE_DEBUG',
'MODULE_SHIPPING_FREIGHTQUOTE_USERNAME',
'MODULE_SHIPPING_FREIGHTQUOTE_PASSWORD',
'MODULE_SHIPPING_FREIGHTQUOTE_SERVICE_TYPE',
'MODULE_SHIPPING_FREIGHTQUOTE_SHIP_ZIP',
'MODULE_SHIPPING_FREIGHTQUOTE_SHIP_COUNTRY',
'MODULE_SHIPPING_FREIGHTQUOTE_LOADING_DOCK',
'MODULE_SHIPPING_FREIGHTQUOTE_RESIDENCE',
'MODULE_SHIPPING_FREIGHTQUOTE_CONSTRUCTION_SITE',
'MODULE_SHIPPING_FREIGHTQUOTE_BLIND',
'MODULE_SHIPPING_FREIGHTQUOTE_PRICE_MODIFIER',
'MODULE_SHIPPING_FREIGHTQUOTE_HANDLING',
'MODULE_SHIPPING_FREIGHTQUOTE_TAX_CLASS',
'MODULE_SHIPPING_FREIGHTQUOTE_ZONE',
'MODULE_SHIPPING_FREIGHTQUOTE_SORT_ORDER',
'MODULE_SHIPPING_FREIGHTQUOTE_DELIVERY_LOCATION'
);
}
}
?>
I changed
Bookmarks