Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

No quotes are given back from server


Recommended Posts

I still haven't gotten eShipper to work yet, but I am close.

 

I just get a null error. I have no idea why.

 

here are the error messages echoed out in the elogger.php. the error_message is what i added.

 

error_message:------------------------------------------

error_message:URL: http://www.e-shipper.net:80/rpc2

error_message:REQUEST:

error_message:RESPONSE: : :

error_message:Parsing XML file...

error_message:Parsed new data element:

error_message:Parsed new data element:

error_message:Parsed new data element:

error_message:Parsed new data element:

error_message:Something wrong happened

error_message:Error reported by the server: null

 

Any thoughts?

Link to comment
Share on other sites

paste Your shipping MOdule.

Probably register globals resulting in blank or some other bug.

 

Satish

Ask/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

Here is the definition file catalog/includes/languages/english/modules/shipping/eshipper.php

<?php

/*

Copyright © 2008 Only Best Rated (http://www.onlybestrated.com)

 

eShipper integration

contribution for osCommerce

ver 1.0 January 1, 2008

Shimon Pozin

Only Best Rated, Inc.

www.onlybestrated.com

[email protected]

Please use the osC forum for support.

Released under the GNU General Public License

 

This contribution is based on UPS XML contribution:

http://addons.oscommerce.com/info/1323

*/

 

define(MODULE_SHIPPING_ESHIPPER_TEXT_TITLE, 'eShipper Courier Services');

define(MODULE_SHIPPING_ESHIPPER_TEXT_DESCRIPTION, 'eShipper service');

define(MODULE_SHIPPING_ESHIPPER_TEXT_IF_YOU_PREFER, 'If you prefer to use eShipper as your shipping method, please contact');

define(NO_QUOTES_AVAILABLE, 'No quotes available');

define(NO_AVAILABLE_SERVICES, 'No shipping services were selected in configuration of the module');

define(NO_QUOTES, 'No quotes available for this destination');

define(NO_QUOTES_ALLOWED, 'No allowed quotes for this destination');

?>

 

 

Here is the main file from catalog/includes/modules/shipping/eshipper.php

<?php

 

/*

Copyright © 2008 Only Best Rated (http://www.onlybestrated.com)

 

eShipper integration

contribution for osCommerce

ver 1.0 January 1, 2008

Shimon Pozin

Only Best Rated, Inc.

www.onlybestrated.com

[email protected]

Please use the osC forum for support.

Released under the GNU General Public License

 

This contribution is based on UPS XML contribution:

http://addons.oscommerce.com/info/1323

*/

 

/*

Shipping module interface

function quote($method = '');

Main function returning array of quotes in the following format:

quotes[$i]['icon'] Shipping vendor's icon (Fedex, Canada Post, UPS etc.)

quotes[$i]['module'] Shipping vendor's name

quotes[$i]['error'] error description if any

quotes[$i]['id'] ID of the shipping vendor

quotes[$i]['methods'] Collection of methods available from give shipping vendor

quotes[$i]['methods'][$j]['id'] ID of the specific shipping method of given vendor

quotes[$i]['methods'][$j]['title'] Name of the shipping method

quotes[$i]['methods'][$j]['title'] Cost of shipping by given shipping method

 

function install();

Install procedure for given module (usually just sets configuration parameters)

function remove();

Remove procedure for given module

function keys();

Returns all configuration keys associated with given modul

function check();

Returns number of configuration keys (called by admin/modules.php)

*/

require(DIR_FS_CATALOG . '/' . DIR_WS_CLASSES . 'eshipper_service.php');

require(DIR_FS_CATALOG . '/' . DIR_WS_CLASSES . 'quote_request_builder.php');

require_once(DIR_FS_CATALOG . '/' . DIR_WS_CLASSES . 'elogger.php');

require_once(DIR_FS_CATALOG . '/' . DIR_WS_CLASSES . 'xmldocument_ex.php');

class eShipper {

 

//"constructor"

function eShipper() {

global $order;

 

$this->logger = new elogger();

 

$this->enabled_services = split(',', MODULE_SHIPPING_ESHIPPER_TYPES);

 

// Use this array if you need to add service-specific information, such as service delivery times

$this->shipping_services_suffix = array

(

1 => '(Next business day by 10:30 am)',

2 => '(Next business day by 8:00 or 8:30 am)',

3 => '(1 - 5 business days)',

4 => '',

5 => '',

6 => '',

7 => '',

8 => '',

9 => '',

10 => '',

11 => '',

12 => '',

13 => '(3 - 6 business days)',

14 => '',

15 => '',

16 => '',

17 => '',

502 => '',

503 => '',

504 => '',

505 => '',

506 => '',

507 => '(1 - 3 months)',

508 => '',

600 => '',

601 => '',

602 => '',

603 => '(3 to 5 business days)',

604 => '',

605 => '',

606 => '',

607

);

 

$this->available_services = $this->get_available_services($this->enabled_services);

 

$this->code = 'eshipper';

$this->title = MODULE_SHIPPING_ESHIPPER_TEXT_TITLE;

$this->description = MODULE_SHIPPING_ESHIPPER_TEXT_DESCRIPTION; // Not used in current version

$this->sort_order = MODULE_SHIPPING_ESHIPPER_SORT_ORDER; // Left for similarity with other shipping modules, but in none of them it's used.

$this->icon = DIR_WS_ICONS . 'shipping_eshipper.gif';

$this->tax_class = MODULE_SHIPPING_ESHIPPER_TAX_CLASS;

$this->enabled = ((MODULE_SHIPPING_ESHIPPER_STATUS == 'True') ? true : false);

$this->shipper_id = MODULE_SHIPPING_ESHIPPER_ID;

$this->access_username = MODULE_SHIPPING_ESHIPPER_USERNAME;

$this->access_password = MODULE_SHIPPING_ESHIPPER_PASSWORD;

$this->origin_company = MODULE_SHIPPING_ESHIPPER_COMPANY;

$this->origin_address1 = MODULE_SHIPPING_ESHIPPER_ADDRESS1;

$this->origin_address2 = MODULE_SHIPPING_ESHIPPER_ADDRESS2;

$this->origin_city = MODULE_SHIPPING_ESHIPPER_CITY;

$this->origin_stateprov = MODULE_SHIPPING_ESHIPPER_STATEPROV;

$this->origin_country = MODULE_SHIPPING_ESHIPPER_COUNTRY;

$this->origin_postalcode = MODULE_SHIPPING_ESHIPPER_POSTALCODE;

$this->package_type = MODULE_SHIPPING_ESHIPPER_PACKAGE_TYPE;

$this->weight_unit;

$this->unit_length;

$this->handling_fee = MODULE_SHIPPING_ESHIPPER_HANDLING;

$this->quote_type_pickup = MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE_PICKUP;

$this->quote_type = MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE;

$this->today = date("Ymd");

$this->packing_algorithm = '';

$this->boxesToShip = array();

$this->item = array();

 

if (($this->enabled == true) && ((int)MODULE_SHIPPING_ESHIPPER_ZONE > 0)) {

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_ESHIPPER_ZONE . "' 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 ($check_flag == false) {

$this->enabled = false;

}

}

}

 

// Get shipping quote for particular items in the shopping cart

function quote($method = '') {

global $order, $shipping_weight, $shipping_num_boxes, $total_weight, $cart;

 

// Prepare shipment parameters before asking for quote. Three major components are:

// weight/dimensions;origin;destination

// This assumption is safe for all shipping modules

 

// Pack products using algorithm defined in the configuration

if(strlen(MODULE_SHIPPING_ESHIPPER_PACKING_ALGORITHM) != 0) {

include(DIR_FS_CATALOG . '/' . DIR_WS_CLASSES . MODULE_SHIPPING_ESHIPPER_PACKING_ALGORITHM . '.php');

$this->packing_algorithm = MODULE_SHIPPING_ESHIPPER_PACKING_ALGORITHM;

$packing = new $this->packing_algorithm;

$this->boxesToShip = $packing->packProducts($cart->get_products());

$this->total_weight = $packing->getTotalWeight();

$this->weight_unit = $packing->getWeightUnit();

}

else {

$this->logger->log("Packing algorithm is not defined in configuration. Leaving...");

return NO_QUOTES_AVAILABLE;

}

 

$shipping_num_boxes = count($this->boxesToShip);

 

$quote = $this->_eShipperQuote();

 

// Add general header for this shipping vendor

$this->quotes = array('id' => $this->code, 'module' => $this->title . ' (' . $shipping_num_boxes . (shipping_num_boxes > 1 ? ' pkg(s) x ' : ' pkg x ') . $this->total_weight . ' ' . strtolower($this->weight_unit) . ' total)');

 

// Build quotes array according to the general rules of every shipping module (see header of this file)

if ((is_array($quote)) && (sizeof($quote) > 0)) {

 

$methods = array();

for ($i=0; $i < sizeof($quote); $i++) {

list($type, $cost) = each($quote[$i]);

if ( $method == '' || $method == $type ) {

$methods[] = array('id' => $type, 'title' => $type, 'cost' => ($this->handling_fee + $cost));

}

}

 

if ($this->tax_class > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

}

 

$this->quotes['methods'] = $methods;

} else {

$errmsg = $quote;

$errmsg .= '<br>' . MODULE_SHIPPING_ESHIPPER_TEXT_IF_YOU_PREFER . ' ' . STORE_NAME.' via <a href="mailto:'. STORE_OWNER_EMAIL_ADDRESS . '"></a>.';

$this->quotes = array('module' => $this->title, 'error' => $errmsg);

}

 

 

 

if (tep_not_null($this->icon)) {

$this->quotes['icon'] = tep_image($this->icon, $this->title);

}

 

return $this->quotes;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable EShipper Shipping', 'MODULE_SHIPPING_ESHIPPER_STATUS', 'False', 'Do you want to offer E-Shipper shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable live mode', 'MODULE_SHIPPING_ESHIPPER_MODE', 'False', 'Live mode?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('EShipper Rates Username', 'MODULE_SHIPPING_ESHIPPER_USERNAME', '', 'Enter your EShipper Services account username.', '6', '2', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('EShipper Rates Password', 'MODULE_SHIPPING_ESHIPPER_PASSWORD', '', 'Enter your EShipper Services account password.', '6', '3', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Packaging Type', 'MODULE_SHIPPING_ESHIPPER_PACKAGE_TYPE', 'Package', 'What kind of packaging do you use?', '6', '4', 'tep_cfg_select_option(array(\'Courier Pak\', \'Envelope\', \'Package\', \'Pallet\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipper ID', 'MODULE_SHIPPING_ESHIPPER_ID', '0', 'Shipper ID.', '6', '5', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipper Company', 'MODULE_SHIPPING_ESHIPPER_COMPANY', '', 'Shipper Company Name.', '6', '5', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Address 1', 'MODULE_SHIPPING_ESHIPPER_ADDRESS1', '', 'Enter the origin Address 1.', '6', '7', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Address 2', 'MODULE_SHIPPING_ESHIPPER_ADDRESS2', '', 'Enter the origin Address 2.', '6', '8', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin City', 'MODULE_SHIPPING_ESHIPPER_CITY', '', 'Enter the name of the origin city.', '6', '9', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin State/Province', 'MODULE_SHIPPING_ESHIPPER_STATEPROV', '', 'Enter the two-letter code for your origin state/province.', '6', '10', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Country', 'MODULE_SHIPPING_ESHIPPER_COUNTRY', '', 'Enter the two-letter code for your origin country.', '6', '11', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Zip/Postal Code', 'MODULE_SHIPPING_ESHIPPER_POSTALCODE', '', 'Enter your origin zip/postalcode.', '6', '12', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Pick-up Type', 'MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE_PICKUP', 'Commercial', 'Type of pick-up facility', '6', '13', 'tep_cfg_select_option(array(\'Commercial\', \'Residential\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Delivery Type', 'MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE', 'Residential', 'Type of delivery facility', '6', '14', 'tep_cfg_select_option(array(\'Commercial\', \'Residential\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_ESHIPPER_HANDLING', '0', 'Handling fee for this shipping method.', '6', '15', now())");

tep_db_query("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_ESHIPPER_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '16', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("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_ESHIPPER_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '17', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("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_ESHIPPER_SORT_ORDER', '10', 'Sort order of display. Lowest is displayed first.', '6', '18', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Methods', 'MODULE_SHIPPING_ESHIPPER_TYPES', '', 'Select the services to be offered.', '6', '19', 'tep_cfg_select_multioption(" .

"array(".

"\'FedEx Priority\'," .

"\'FedEx First Overnight\'," .

"\'FedEx Ground\'," .

"\'FedEx Standard Overnight\'," .

"\'FedEx 2nd Day\'," .

"\'Purolator Air\'," .

"\'Purolator Air 9AM\'," .

"\'Purolator Air 1030\'," .

"\'Puroletter\'," .

"\'Puroletter 9AM\'," .

"\'Puroletter 1030\'," .

"\'PuroPak\'," .

"\'PuroPak 9AM\'," .

"\'PuroPak 1030\'," .

"\'Purolator Ground\'," .

"\'Canada Worldwide Same Day\'," .

"\'Canada Worldwide Next Flight Out\'," .

"\'Canada Worldwide Air Freight\'," .

"\'Canada Worldwide LTL\'," .

"\'DHL Express\'," .

"\'DHL Express 10:30AM\'," .

"\'DHL Express Saturday\'," .

"\'DHL Express Second Day\'," .

"\'DHL Next Afternoon\'," .

"\'DHL Ground\'," .

"\'DHL International Express\'," .

"\'UPS Express\'," .

"\'UPS Expedited\'," .

"\'UPS Worldwide Express\'," .

"\'UPS Worldwide Expedited\'," .

"\'UPS Standard (Ground)\'," .

"\'UPS Express Early A.M.\'," .

"\'UPS Three-Day Select\'," .

"\'UPS Saver\'," .

"\'Canada Post Priority\'," .

"\'Canada Post Xpress Post\'," .

"\'Canada Post Expedited\'," .

"\'Canada Post Regular\'," .

"\'Canada Post Xpress Post USA\'," .

"\'Canada Post Xpress Post INTL\'," .

"\'Canada Post Air Parcel INTL\'," .

"\'Canada Post Surface Parcel INTL\'," .

"\'Canada Post Expedited Parcel USA\'" .

"), ', now())");

 

tep_db_query("insert into " . TABLE_CONFIGURATION

. " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('EShipper Packing Algorithm', 'MODULE_SHIPPING_ESHIPPER_PACKING_ALGORITHM', 'PackingInSingleBox', 'Select eShipper packing algorithm', '6', '22', 'tep_cfg_select_option(array(\'PackingInSingleBox\', \'PackingUPSStyle\'), ', now())");

}

 

function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION

. " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

// add MODULE_SHIPPING_eshipperXML_TYPES to end of array

function keys() {

return array

(

'MODULE_SHIPPING_ESHIPPER_STATUS',

'MODULE_SHIPPING_ESHIPPER_MODE',

'MODULE_SHIPPING_ESHIPPER_USERNAME',

'MODULE_SHIPPING_ESHIPPER_PASSWORD',

'MODULE_SHIPPING_ESHIPPER_PACKAGE_TYPE',

'MODULE_SHIPPING_ESHIPPER_ID',

'MODULE_SHIPPING_ESHIPPER_COMPANY',

'MODULE_SHIPPING_ESHIPPER_ADDRESS1',

'MODULE_SHIPPING_ESHIPPER_ADDRESS2',

'MODULE_SHIPPING_ESHIPPER_CITY',

'MODULE_SHIPPING_ESHIPPER_STATEPROV',

'MODULE_SHIPPING_ESHIPPER_COUNTRY',

'MODULE_SHIPPING_ESHIPPER_POSTALCODE',

'MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE_PICKUP',

'MODULE_SHIPPING_ESHIPPER_QUOTE_TYPE',

'MODULE_SHIPPING_ESHIPPER_HANDLING',

'MODULE_SHIPPING_ESHIPPER_TAX_CLASS',

'MODULE_SHIPPING_ESHIPPER_ZONE',

'MODULE_SHIPPING_ESHIPPER_SORT_ORDER',

'MODULE_SHIPPING_ESHIPPER_TYPES',

'MODULE_SHIPPING_ESHIPPER_PACKING_ALGORITHM'

);

}

 

// Used from admin/modules.php

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ESHIPPER_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

// Actual XML request for the shipping quote

// Only relevant fields are entered

function _eShipperQuote() {

global $order, $cart;

 

$request = new quote_request_builder();

 

$request->addHeader($this->access_username, $this->access_password);

 

$request->addRequestType('QuoteRequest', array(/*'insuranceAmount' => $cart->show_total()*/));

 

$address_from = new address(

$this->origin_company,

$this->origin_address1,

$this->origin_address2,

$this->origin_city,

$this->origin_stateprov,

$this->origin_country,

$this->origin_postalcode,

$this->quote_type_pickup,

$this->shipper_id

);

 

$request->addAddressFrom($address_from, false);

 

$address_to = new address(

$order->delivery['company'],

$order->delivery['street_address'],

"", // address2

$order->delivery['city'],

$order->delivery['state'],

$order->delivery['country']['iso_code_2'],

$order->delivery['postcode'],

$this->quote_type

);

 

$request->addAddressTo($address_to, false);

 

$request->addPackages($this->package_type, $this->boxesToShip);

 

$request->addFooter();

 

$quoteRequest = $request->buildRequest();

 

// post request $strXML;

$service = new eshipper_service();

$xmlResult = $service->post($quoteRequest);

 

if($xmlResult == FALSE) { // error occured during transmission

return $service->processError($xmlResult);

}

 

return $this->_parseResult($xmlResult);

}

 

// Parse XML message returned by the post server.

function _parseResult($xmlResult) {

 

$doc = new XMLDocument();

$xp = new XMLParser();

$xp->setDocument($doc);

$xp->parse($xmlResult);

$doc = $xp->getDocument();

 

$root = $doc->getRoot();

 

// Get error code.

 

if($root == null) {

$this->logger->log("Could not find any quotes");

return NO_QUOTES_AVAILABLE;

}

 

$errorElement = $root->getElementByName("ErrorReply");

 

// Something wrong happened

if ($errorElement != null) {

$this->logger->log("Something wrong happened");

return $this->_processError($errorElement);

}

 

// If not errors occured, we have quotes

$quoteReply = $root->getElementByName("QuoteReply");

$quotes = $quoteReply->getElementsByName("Quote");

$number_of_quotes = count($quotes);

 

$this->logger->log("Number of quotes found: " . $number_of_quotes);

 

$quotes_result = array();

 

$index_quote = 0;

 

$this->logger->log("Available services:" . print_r($this->available_services, true));

 

if( 0 == count($this->available_services) ) {

return NO_AVAILABLE_SERVICES;

}

 

if( 0 == $number_of_quotes ) {

return NO_QUOTES;

}

 

for ($i = 0; $i < $number_of_quotes; $i++) {

 

$attr = $quotes[$i]->getAttributes();

$serviceID = $attr['serviceId'];

if (array_search($serviceID, $this->available_services))

{

 

$carrierID = $attr['carrierId'];

$carrier = $attr['carrierName'];

 

$serviceName = $attr['serviceName'];

$daysInTransit = $attr['transitDays'];

$totalCharge = $attr['totalCharge'];

 

$this->logger->log("serviceId=" . $serviceID);

$this->logger->log(" Carrier: " . $carrier);

$this->logger->log(" Service name: " . $serviceName);

$this->logger->log(" Total charge: " . $totalCharge);

$this->logger->log(" Days in transit: " . $daysInTransit);

 

$title = $carrier . ': ' . $serviceName . ' ' . $this->shipping_services_suffix[$serviceID] . ' <sub>[' . $serviceID . ']</sub>';

$quotes_result[$index_quote] = array($title => $totalCharge);

$index_quote++;

}

} // for

 

if( 0 == $index_quote ) {

return NO_QUOTES_ALLOWED;

}

 

$this->logger->log("Available quotes: " . print_r($quotes_result, true));

 

usort($quotes_result, 'compare');

 

$this->logger->log("Available quotes: " . print_r($quotes_result, true));

 

return $quotes_result;

}

 

function _processError($errorElement) {

$error = $errorElement->getElementByName('Error');

if ($error != null) {

$errorAttr = $error->getAttributes();

$errorMsg = $errorAttr['Message'];

$this->logger->log("Error reported by the server: " . $errorMsg);

return $errorMsg;

} else {

return NO_QUOTES_AVAILABLE;

}

}

 

function get_available_services($service_whitelist) {

$services_array = array(

"FedEx Priority" => 1,

"FedEx First Overnight" => 2,

"FedEx Ground" => 3,

"FedEx Standard Overnight" => 28,

"FedEx 2nd Day" => 29,

"Purolator Air" => 4,

"Purolator Air 9AM" => 5,

"Purolator Air 1030" => 6,

"Puroletter" => 7,

"Puroletter 9AM" => 8,

"Puroletter 1030" => 9,

"PuroPak" => 10,

"PuroPak 9AM" => 11,

"PuroPak 1030" => 12,

"Purolator Ground" => 13,

"Purolator Ground 9AM" => 19,

"Purolator Ground 1030" => 20,

"Canada Worldwide Same Day" => 14,

"Canada Worldwide Next Flight Out" => 15,

"Canada Worldwide Air Freight" => 16,

"Canada Worldwide LTL" => 17,

"DHL Express" => 100,

"DHL Express 10:30AM" => 101,

"DHL Express Saturday" => 102,

"DHL Express Second Day" => 103,

"DHL Next Afternoon" => 104,

"DHL Ground" => 105,

"DHL International Express" => 106,

"UPS Express" => 600,

"UPS Expedited" => 601,

"UPS Worldwide Express" => 602,

"UPS Worldwide Expedited" => 603,

"UPS Standard (Ground)" => 604,

"UPS Express Early A.M." => 605,

"UPS Three-Day Select" => 606,

"UPS Saver" => 607,

"Canada Post Priority" => 500,

"Canada Post Xpress Post" => 501,

"Canada Post Expedited" => 502,

"Canada Post Regular" => 503,

"Canada Post Xpress Post USA" => 504,

"Canada Post Xpress Post INTL" => 505,

"Canada Post Air Parcel INTL" => 506,

"Canada Post Surface Parcel INTL" => 507,

"Canada Post Expedited Parcel USA" => 508

);

 

foreach($service_whitelist as $service_name) {

$trimmed_service_name = trim($service_name);

$available_services[$trimmed_service_name] = $services_array[$trimmed_service_name];

}

 

return $available_services;

}

}

 

function compare($x, $y)

{

$x_values = array_values($x);

$y_values = array_values($y);

if ( $x_values[0] == $y_values[0] ) {

return 0;

} else {

return ( $x_values[0] < $y_values[0] ) ? -1 : 1;

}

}

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...