Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Multi_Vendor_Shipping new thread


blucollarguy

Recommended Posts

Im trying to add the new USPS shipping module 2.9.6 to MVS.

 

I cant seem to get the insurance part to work

 

anyone done this?

 

Everything works but it dont show up in the field so Im thinking I have to change something in vendor_shipping module.

Edited by drillsar
Link to comment
Share on other sites

Im trying to add the new USPS shipping module 2.9.6 to MVS.

 

I cant seem to get the insurance part to work

 

anyone done this?

 

Everything works but it dont show up in the field so Im thinking I have to change something in vendor_shipping module.

See Rick's post above. Maybe the two of you can get this working.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Ack! Stupid thing isn't notifying me again....

 

Rick: The first error in that stack indicates that the constant is not getting the $vendors_id added onto the end. That definitely needs to be fixed. For the rest, the first thing I would do is uninstall and reinstall the module. If that doesn't do it, look at the install method -- are all of the constants correct, including the $vendors_id part?

 

Regards

Jim

Jim,

 

OK. I got rid of most of the checkout errors by uninstalling my new module, installing the old module and then uninstalling it and running 2 SQL scripts included with the new module (I had overlooked the SQL somehow), and then reinstalling the new module. Also, I found a typo in one of the insure constants, $vendors_is instead of $vendors_id. Fixing that hat got rid of the last checkout error. Now everything seems to be working except that insurance is not being added to the shipping cost and in admin, Sort Order doesn't work. I think the error with insurance is in the constants, but I'm not sure how to handle them. Here's the code for the insurance functions.

// Insurance module by Kevin Shelton

// divide the value of the order among the packages based on the order total or subtotal depending on whether or not you have configured to insure tax

if (constant('MODULE_SHIPPING_USPS_INSURE_TAX_' . $vendors_id) == 'True') {
 $costperpkg = $order->info['total'] / $shipping_num_boxes;}
else {
 $costperpkg = $order->info['subtotal'] / $shipping_num_boxes;}

// retrieve the maximum allowed insurance for the destination country and if the package value exceeds it then set package value to the maximum allowed

$maxins = $this->countryinsure[$order->delivery['country']['iso_code_2']];
if ($costperpkg > $maxins) $costperpkg = $maxins;

// if insurance not allowed for destination or insurance is turned off add nothing to shipping cost

if (($maxins == 0) || (constant('MODULE_SHIPPING_USPS_INSURE_' . $vendors_id) == 'False')) {
 $insurance = 0; }

// US and Canada share the same insurance calculation (though not the same maximum)

else if (($order->delivery['country']['iso_code_2'] == 'US') || ($order->delivery['country']['iso_code_2'] == 'CA')){
if ($costperpkg<=50) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS1_' . $vendors_id);}
else if ($costperpkg<=100) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS2_' . $vendors_id);}
	else if ($costperpkg<=200) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS3_' . $vendors_id);}
	else if ($costperpkg<=300) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS4_' . $vendors_id);}
else {
	$insurance = constant('MODULE_SHIPPING_USPS_INS4_' . $vendors_id) + ((ceil($costperpkg/100) -3) * constant('MODULE_SHIPPING_USPS_INS5_' . $vendors_id)); }
 }

// if insurance allowed and is not US or Canada then calculate international insurance

else {
if ($costperpkg<=50) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS6_' . $vendors_id);}
else if ($costperpkg<=100) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS7_' . $vendors_id);}
else {
	$insurance = constant('MODULE_SHIPPING_USPS_INS7_' . $vendors_id) + ((ceil($costperpkg/100) - 1) * constant('MODULE_SHIPPING_USPS_INS8_' . $vendors_id)); }
}

Since the insurance constants are all of the form "$insurance=constant('MODULE_SHIPPING_USPS_INS1_' . $vendors_id);, how do I define 8 constants that all begin with "$insurance=" but are different?

 

Also, what might be preventing Sort Order from working for me?

 

Thanks,

Rick

Link to comment
Share on other sites

Im trying to add the new USPS shipping module 2.9.6 to MVS.

 

I cant seem to get the insurance part to work

 

anyone done this?

 

Everything works but it dont show up in the field so Im thinking I have to change something in vendor_shipping module.

Drillsar,

 

Take a look at the Troubleshooting section of the USPS 2.9.6 install text. Make sure you change FUNCTION_SET from VARCHAR to TEXT and be sure to run the 2 SQL scripts. The VARCHAR change made all of the field in admin populate for me.

 

Also, see my previous message. I have everything working in admin except Sort Order and in Checkout, the only thing that doesn't work is the insurance calculations.

 

Rick

Link to comment
Share on other sites

Ack! Stupid thing isn't notifying me again....

 

macombmarineparts: I'm working on that module right now (I need to have estimates on individual products from the product page as well as the full cart) and I don't see that problem. What modules do you have installed? Remove everything that requires an external server (USPS, UPS, FedEx, etc.) and try with the internal modules (e.g. Fixed Rate) only. You could be seeing a connection delay from the external server.

 

Rick: The first error in that stack indicates that the constant is not getting the $vendors_id added onto the end. That definitely needs to be fixed. For the rest, the first thing I would do is uninstall and reinstall the module. If that doesn't do it, look at the install method -- are all of the constants correct, including the $vendors_id part?

 

damdamletouffu: I don't see anything wrong, at least on a quick runthrough. I'll take another look in a bit.

 

Regards

Jim

 

Jim:

Using just the UPS XML module - the thing is that it work with no problems when not logged in. I'm guessing it's in where the data is transfered from the clients account?? Still think it could be a server issue if it works when not logged in?

 

Thanks

Pete

Link to comment
Share on other sites

Drillsar,

 

Take a look at the Troubleshooting section of the USPS 2.9.6 install text. Make sure you change FUNCTION_SET from VARCHAR to TEXT and be sure to run the 2 SQL scripts. The VARCHAR change made all of the field in admin populate for me.

 

Also, see my previous message. I have everything working in admin except Sort Order and in Checkout, the only thing that doesn't work is the insurance calculations.

 

Rick

 

ok could my problem be this?

 

unction tep_cfg_select_multioption

 

I had to uncomment this since MVS uses this

Link to comment
Share on other sites

<snipped code>

Since the insurance constants are all of the form "$insurance=constant('MODULE_SHIPPING_USPS_INS1_' . $vendors_id);, how do I define 8 constants that all begin with "$insurance=" but are different?

 

Also, what might be preventing Sort Order from working for me?

 

Thanks,

Rick

Those constants would all need to be defined in the install method (if you want to be able to change them in the Admin) or in the class constructor. I don't like all of those numbered constants, and I'm not certain they are necessary. You could do with only two (domestic and international) by using the same list as the Zones module uses. Aside from that, I don't see a problem with this code. It's likely that the problem is somewhere else, or maybe I'm just not seeing the whole picture.

 

Sort Order never worked in the official release. If you search through this thread, I believe that someone posted a fix for this.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Jim:

Using just the UPS XML module - the thing is that it work with no problems when not logged in. I'm guessing it's in where the data is transfered from the clients account?? Still think it could be a server issue if it works when not logged in?

 

Thanks

Pete

No, That was just a quickie attempt to find the problem. If it works with one of the internal modules and not with UPSXML, that would tell you that it is most likely the Zip code is not being passed, since that is what UPS requires. That situation should really result in an error, not in the thing hanging, so I'm not convinced that's the answer either. You might try setting $debug = 'yes' and check the data to see what's actually being passed.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Sort Order never worked in the official release. If you search through this thread, I believe that someone posted a fix for this.

 

Regards

Jim

OK. Sort order fix...

 

Replace this...

	function sort_order($vendors_id='1') {
  if (defined (@constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id))) {
	$this->sort_order = @constant('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);
  } else {
	$this->sort_order = '0';
  }
  return $this->sort_order;
}

With this...

	function sort_order($vendors_id='1') {
 $sort_order = constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);
 if (isset ($sort_order)) {		$this->sort_order = $sort_order;
  } else {
	$this->sort_order = '0';
  }
  return $this->sort_order;
}

 

Drillsar,

 

I didn't modify my catalog/admin/includes/functions/general.php because I have the "tep_cfg_select_multioption" configured elsewhere.

 

Rick

Link to comment
Share on other sites

OK. Sort order fix...

<snipped>

Rick

I don't think that will work quite the way you want. $sort_order is always set, so the else will never happen. Also the constant() will throw an error if the module is installed but not for the current vendor (you need the @ in front.)

 

The original version really should work. I think PHP is just a bit buggy....

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

No, That was just a quickie attempt to find the problem. If it works with one of the internal modules and not with UPSXML, that would tell you that it is most likely the Zip code is not being passed, since that is what UPS requires. That situation should really result in an error, not in the thing hanging, so I'm not convinced that's the answer either. You might try setting $debug = 'yes' and check the data to see what's actually being passed.

 

Regards

Jim

 

I see where to change the code to yes to start the debug but how do you actually get the data thats being passed?

 

Thanks again

Pete

Link to comment
Share on other sites

I don't think that will work quite the way you want. $sort_order is always set, so the else will never happen. Also the constant() will throw an error if the module is installed but not for the current vendor (you need the @ in front.)

 

The original version really should work. I think PHP is just a bit buggy....

 

Regards

Jim

Jim,

 

The fix for Sort Order came from an older MVS USPS module. I think from the original module I worked on with you and Craig a couple of years ago. I just stole it. I've added @ in front of the constant and it seems to work. I'm also not seeing an error with other vendors that don't have the module installed, but I'll keep on testing before I put this on my live store. Also, I would really like to get the insurance code working.

 

Thanks,

Rick

Link to comment
Share on other sites

here is my usps.php file notice I uncommented the tep_cfg_multioption in admin/includes/functions/general.php:

 

general.php

 

// USPS Methods 2.9

// Alias function for Store configuration values in the Administration Tool

//function tep_cfg_select_multioption($select_array, $key_value, $key = '') {

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

// $name = (($key) ? 'configuration[' . $key . '][]' : 'configuration_value');

// $string .= '<br><input type="checkbox" name="' . $name . '" value="' . $select_array[$i] . '"';

// $key_values = explode( ", ", $key_value);

// if ( in_array($select_array[$i], $key_values) ) $string .= ' CHECKED';

// $string .= '> ' . $select_array[$i];

// }

// $string .= '<input type="hidden" name="' . $name . '" value="--none--">';

// return $string;

//}

////

// Retreive server information

// function tep_get_system_information() {

// global $HTTP_SERVER_VARS;

////

// Retreive server information

 

USPS.php file

 

class usps {

var $code, $title, $description, $icon, $enabled, $countries;

 

// class constructor

function usps() {

global $order;

// Added MVS

// $this->vendors_id = ($products['vendors_id'] <= 0) ? 1 : $products['vendors_id'];

// End ADD

 

$this->code = 'usps';

$this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;

$this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;

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

$this->delivery_country_id = $order->delivery['country']['id'];

$this->delivery_zone_id = $order->delivery['zone_id'];

$this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;

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

 

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_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_USPS_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;

}

}

 

 

$this->types = array('Express' => 'EXPRESS', 'First Class' => 'First-Class Mail', 'Priority' => 'Priority', 'Parcel' => 'Parcel', 'BPM' => 'Bound Printed Material', 'Library' => 'Library', 'Media' => 'Media Mail');

 

$this->intl_types = array('GXG Document' => 'Global Express Guaranteed Document Service',

'GXG Non-Document' => 'Global Express Guaranteed Non-Document Service',

'Express' => 'Global Express Mail (EMS)',

'Priority Lg' => 'Global Priority Mail - Flat-rate Envelope (Large)',

'Priority Sm' => 'Global Priority Mail - Flat-rate Envelope (Small)',

'Priority Var' => 'Global Priority Mail - Variable Weight (Single)',

'Airmail Letter' => 'Airmail Letter-post',

'Airmail Parcel' => 'Airmail Parcel Post',

'Surface Letter' => 'Economy (Surface) Letter-post',

'Surface Post' => 'Economy (Surface) Parcel Post');

 

$this->countries = $this->country_list();

$this->countryinsure = $this->country_maxinsure();

}

// MVS ADD

function sort_order($vendors_id='1') {

$sort_order = @constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);

if (isset ($sort_order)) { $this->sort_order = $sort_order;

} else {

$this->sort_order = '0';

}

return $this->sort_order;

}

 

function tax_class($vendors_id='1') {

$this->tax_class = constant('MODULE_SHIPPING_USPS_TAX_CLASS_' . $vendors_id);

return $this->tax_class;

}

/*

function enabled($vendors_id='1') {

$this->enabled = false;

$status = @constant('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id);

if (isset ($status) && $status != '') {

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

}*/

function enabled($vendors_id='1') {

 

$this->enabled = false;

 

$status = @constant('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id);

 

if (isset ($status) && $status != '') {

 

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

 

}

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_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_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->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'] == $this->delivery_zone_id) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}//if

}//if

return $this->enabled;

}

 

function zones($vendors_id='1') {

/*

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_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_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->delivery_zone_id . "' order by zone_id");

*/

if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_USPS_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_USPS_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $this->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'] == $this->delivery_zone_id) {

$check_flag = true;

break;

} //if

}//while

 

if ($check_flag == false) {

$this->enabled = false;

}//if

}//if

return $this->enabled;

}//function

// EOADD MVS

 

// class methods

// Changed MVS

// function quote($method = '') {

function quote($method = '', $module = '', $vendors_id = '1') {

// EOCHANGE

global $order, $shipping_weight, $shipping_num_boxes, $transittime;

 

if ( tep_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {

$this->_setService($method);

}

 

$this->_setMachinable('False');

$this->_setContainer('None');

$this->_setSize('REGULAR');

// Insurance module by Kevin Shelton

 

// divide the value of the order among the packages based on the order total or subtotal depending on whether or not you have configured to insure tax

 

if (MODULE_SHIPPING_USPS_INSURE_TAX == 'True') {

$costperpkg = $order->info['total'] / $shipping_num_boxes;}

else {

$costperpkg = $order->info['subtotal'] / $shipping_num_boxes;}

 

// retrieve the maximum allowed insurance for the destination country and if the package value exceeds it then set package value to the maximum allowed

 

$maxins = $this->countryinsure[$order->delivery['country']['iso_code_2']];

if ($costperpkg > $maxins) $costperpkg = $maxins;

 

// if insurance not allowed for destination or insurance is turned off add nothing to shipping cost

 

if (($maxins == 0) || (MODULE_SHIPPING_USPS_INSURE == 'False')) {

$insurance = 0; }

 

// US and Canada share the same insurance calculation (though not the same maximum)

 

else if (($order->delivery['country']['iso_code_2'] == 'US') || ($order->delivery['country']['iso_code_2'] == 'CA')){

if ($costperpkg<=50) {

$insurance=MODULE_SHIPPING_USPS_INS1;}

else if ($costperpkg<=100) {

$insurance=MODULE_SHIPPING_USPS_INS2;}

else {

$insurance = MODULE_SHIPPING_USPS_INS2 + ((ceil($costperpkg/100) - 1) * MODULE_SHIPPING_USPS_INS3); }

}

 

// if insurance allowed and is not US or Canada then calculate international insurance

 

else {

if ($costperpkg<=50) {

$insurance=MODULE_SHIPPING_USPS_INS4;}

else if ($costperpkg<=100) {

$insurance=MODULE_SHIPPING_USPS_INS5;}

else {

$insurance = MODULE_SHIPPING_USPS_INS5 + ((ceil($costperpkg/100) - 1) * MODULE_SHIPPING_USPS_INS6); }

}

// usps doesnt accept zero weight

$shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);

$shipping_pounds = floor ($shipping_weight);

$shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));

$this->_setWeight($shipping_pounds, $shipping_ounces);

// Added by Kevin Chen ([email protected]); Fixes the Parcel Post Bug July 1, 2004

// Refer to http://www.usps.com/webtools/htm/Domestic-Rates.htm documentation

// Thanks Ryan

if($shipping_pounds > 35 || $shipping_ounces < 6){

$this->_setMachinable('False');

}

else{

$this->_setMachinable('True');

}

// End Kevin Chen July 1, 2004

 

if (in_array('Display weight', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) {

$shiptitle = ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)';

} else {

$shiptitle = '';

}

 

$uspsQuote = $this->_getQuote($vendors_id);

 

if (is_array($uspsQuote)) {

if (isset($uspsQuote['error'])) {

$this->quotes = array('module' => $this->title,

'error' => $uspsQuote['error']);

} else {

// Added MVS

$vendors_data_query = tep_db_query("select handling_charge,

handling_per_box,

vendor_country,

vendors_zipcode

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*$shipping_num_boxes) {

$handling = $handling_charge;

} else {

$handling = $handling_per_box*$shipping_num_boxes;

}

// EOADD MVS

 

/* Original

$this->quotes = array('id' => $this->code,

'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');

*/

// BOF: UPS USPS

$this->quotes = array('id' => $this->code,

'module' => $this->title . $shiptitle);

 

$methods = array();

$size = sizeof($uspsQuote);

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

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

 

$title = ((isset($this->types[$type])) ? $this->types[$type] : $type);

if(in_array('Display transit time', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) $title .= $transittime[$type];

 

$methods[] = array('id' => $type,

'title' => $title,

'cost' => ($cost + $insurance + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

}

 

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

 

// $this->tax_class = constant(MODULE_SHIPPING_USPS_TAX_CLASS_ . $vendors_id);

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']);

}

}

} else {

$this->quotes = array('module' => $this->title,

'error' => MODULE_SHIPPING_USPS_TEXT_ERROR);

}

 

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

 

return $this->quotes;

}

 

// MVS Added/Changed

// function check() {

function check($vendors_id = '1') {

//EOMVS

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

// MVS Added/Changed

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

$check_query = tep_db_query("select configuration_value from " . TABLE_VENDOR_CONFIGURATION . " where vendors_id = '". $vendors_id ."' and configuration_key = 'MODULE_SHIPPING_USPS_STATUS_" . $vendors_id . "'");

// EOMVS

 

$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 USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS_" . $vendors_id . "', 'True', 'Do you want to offer USPS 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, date_added, vendors_id) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID_" . $vendors_id . "', 'NONE', 'Enter the USPS USERID assigned to you.', '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 ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD_" . $vendors_id . "', 'NONE', 'See USERID, above.', '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, set_function, date_added, vendors_id) values ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER_" . $vendors_id . "', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'tep_cfg_select_option(array(\'test\', \'production\'), ', 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 ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING_" . $vendors_id . "', '0', 'Handling fee for this shipping method.', '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 ('Tax Class', 'MODULE_SHIPPING_USPS_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, use_function, set_function, date_added, vendors_id) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_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, date_added, vendors_id) values ('Sort Order', 'MODULE_SHIPPING_USPS_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, set_function, date_added, vendors_id) values ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_" . $vendors_id . "', 'Express, Priority, First Class, Parcel', 'Select the domestic services to be offered:', '6', '14', 'tep_cfg_select_multioption(array(\'Express\', \'Priority\', \'First Class\', \'Parcel\'), ', 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 ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL_" . $vendors_id . "', 'GXG Document, GXG Non-Document, Express, Priority Lg, Priority Sm, Priority Var, Airmail Letter, Airmail Parcel, Surface Letter, Surface Post', 'Select the international services to be offered:', '6', '15', 'tep_cfg_select_multioption(array(\'GXG Document\', \'GXG Non-Document\', \'Express\', \'Priority Lg\', \'Priority Sm\', \'Priority Var\', \'Airmail Letter\', \'Airmail Parcel\', \'Surface Letter\', \'Surface Post\'), ', 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 ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS_" . $vendors_id . "', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '16', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ', now(), '" . $vendors_id . "')");

//configuration values for insurance

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada to $50', 'MODULE_SHIPPING_USPS_INS1', '1.30', 'US/Canada insurance total up to $50', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada $50-100', 'MODULE_SHIPPING_USPS_INS2', '2.20', 'US/Canada insurance for totals $50.01-$100', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('US/Canada per $100', 'MODULE_SHIPPING_USPS_INS3', '1.00', 'US/Canada for every $100 over $100 add $', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International to $50', 'MODULE_SHIPPING_USPS_INS4', '1.85', 'International insurance total up to $50', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International $50-100', 'MODULE_SHIPPING_USPS_INS5', '2.60', 'International insurance for totals $50.01-$100', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('International per $100', 'MODULE_SHIPPING_USPS_INS6', '1.00', 'International for every $100 over $100 add $', '6', '0', 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 ('Insure Packages', 'MODULE_SHIPPING_USPS_INSURE', 'True', 'Insure packages shipped by USPS?', '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 ('Insure Tax', 'MODULE_SHIPPING_USPS_INSURE_TAX', 'True', 'Insure tax on packages shipped by USPS?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

}

 

function remove($vendors_id) {

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) {

return array('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id, 'MODULE_SHIPPING_USPS_USERID_' . $vendors_id, 'MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id, 'MODULE_SHIPPING_USPS_SERVER_' . $vendors_id, 'MODULE_SHIPPING_USPS_HANDLING_' . $vendors_id, 'MODULE_SHIPPING_USPS_TAX_CLASS_' . $vendors_id, 'MODULE_SHIPPING_USPS_ZONE_' . $vendors_id, 'MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id, 'MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_INTL_' . $vendors_id);

}

 

function _setService($service) {

$this->service = $service;

}

 

function _setWeight($pounds, $ounces=0) {

$this->pounds = $pounds;

$this->ounces = $ounces;

}

 

function _setContainer($container) {

$this->container = $container;

}

 

function _setSize($size) {

$this->size = $size;

}

 

function _setMachinable($machinable) {

$this->machinable = $machinable;

}

 

function _getQuote($vendors_id) {

global $order, $transittime;

// MVS Added

$vendors_data_query = tep_db_query("select vendor_country,

vendors_zipcode

from " . TABLE_VENDORS . "

where vendors_id = '" . (int)$vendors_id . "'"

);

$vendors_data = tep_db_fetch_array($vendors_data_query);

// MVS End

if(in_array('Display transit time', explode(', ', constant('MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id)))) $transit = TRUE;

// EOF: UPS USPS

 

if ($order->delivery['country']['id'] == /*SHIPPING_ORIGIN_COUNTRY*/ $vendors_data['vendor_country']) {

$request = '<RateRequest USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) . '" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">';

 

 

$services_count = 0;

 

if (isset($this->service)) {

$this->types = array($this->service => $this->types[$this->service]);

}

 

$dest_zip = str_replace(' ', '', $order->delivery['postcode']);

if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);

 

reset($this->types);

$allowed_types = explode(", ", constant('MODULE_SHIPPING_USPS_TYPES_' . $vendors_id));

 

while (list($key, $value) = each($this->types)) {

 

if ( !in_array($key, $allowed_types) ) continue;

 

$request .= '<Package ID="' . $services_count . '">' .

'<Service>' . $key . '</Service>' .

'<ZipOrigination>' . /*SHIPPING_ORIGIN_ZIP*/ $vendors_data['vendors_zipcode'] . '</ZipOrigination>' .

'<ZipDestination>' . $dest_zip . '</ZipDestination>' .

'<Pounds>' . $this->pounds . '</Pounds>' .

'<Ounces>' . $this->ounces . '</Ounces>' .

'<Container>' . $this->container . '</Container>' .

'<Size>' . $this->size . '</Size>' .

'<Machinable>' . $this->machinable . '</Machinable>' .

'</Package>';

 

if($transit){

$transitreq = 'USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) .

'" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">' .

'<OriginZip>' . $vendors_data['vendors_zipcode'] . '</OriginZip>' .

'<DestinationZip>' . $dest_zip . '</DestinationZip>';

 

switch ($key) {

case 'Express': $transreq[$key] = 'API=ExpressMail&XML=' .

urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');

break;

case 'Priority': $transreq[$key] = 'API=PriorityMail&XML=' .

urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');

break;

case 'Parcel': $transreq[$key] = 'API=StandardB&XML=' .

urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');

break;

default: $transreq[$key] = '';

break;

}

}

 

$services_count++;

}

$request .= '</RateRequest>';

 

$request = 'API=Rate&XML=' . urlencode($request);

} else {

$request = '<IntlRateRequest USERID="' . constant('MODULE_SHIPPING_USPS_USERID_' . $vendors_id) . '" PASSWORD="' . constant('MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id) . '">' .

'<Package ID="0">' .

'<Pounds>' . $this->pounds . '</Pounds>' .

'<Ounces>' . $this->ounces . '</Ounces>' .

'<MailType>Package</MailType>' .

'<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .

'</Package>' .

'</IntlRateRequest>';

 

$request = 'API=IntlRate&XML=' . urlencode($request);

}

 

switch (constant('MODULE_SHIPPING_USPS_SERVER_' . $vendors_id)) {

case 'production': $usps_server = 'production.shippingapis.com';

$api_dll = 'shippingapi.dll';

break;

case 'test':

default: $usps_server = 'testing.shippingapis.com';

$api_dll = 'ShippingAPITest.dll';

break;

}

 

$body = '';

 

$http = new httpClient();

if ($http->Connect($usps_server, 80)) {

$http->addHeader('Host', $usps_server);

$http->addHeader('User-Agent', 'osCommerce');

$http->addHeader('Connection', 'Close');

 

if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();

// mail('[email protected]','USPS rate quote response',$body,'From: <[email protected]>');

if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {

while (list($key, $value) = each($transreq)) {

if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();

}

}

 

$http->Disconnect();

 

} else {

return false;

}

 

$response = array();

while (true) {

if ($start = strpos($body, '<Package ID=')) {

$body = substr($body, $start);

$end = strpos($body, '</Package>');

$response[] = substr($body, 0, $end+10);

$body = substr($body, $end+9);

} else {

break;

}

}

 

$rates = array();

if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {

if (sizeof($response) == '1') {

if (ereg('<Error>', $response[0])) {

$number = ereg('<Number>(.*)</Number>', $response[0], $regs);

$number = $regs[1];

$description = ereg('<Description>(.*)</Description>', $response[0], $regs);

$description = $regs[1];

 

return array('error' => $number . ' - ' . $description);

}

}

 

$n = sizeof($response);

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

if (strpos($response[$i], '<Postage>')) {

$service = ereg('<Service>(.*)</Service>', $response[$i], $regs);

$service = $regs[1];

$postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);

$postage = $regs[1];

 

$rates[] = array($service => $postage);

 

if ($transit) {

switch ($service) {

case 'Express': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} else {

$time = 'Tomorrow by ' . $time;

}

break;

case 'Priority': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} elseif ($time == '1') {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;

} else {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

}

break;

case 'Parcel': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);

$time = $tregs[1];

if ($time == '' || $time == 'No Data') {

$time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

} elseif ($time == '1') {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;

} else {

$time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

}

break;

case 'First Class': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;

break;

default: $time = '';

break;

}

if ($time != '') $transittime[$service] = ' (' . $time . ')';

}

}

}

} else {

if (ereg('<Error>', $response[0])) {

$number = ereg('<Number>(.*)</Number>', $response[0], $regs);

$number = $regs[1];

$description = ereg('<Description>(.*)</Description>', $response[0], $regs);

$description = $regs[1];

 

return array('error' => $number . ' - ' . $description);

} else {

$body = $response[0];

$services = array();

while (true) {

if ($start = strpos($body, '<Service ID=')) {

$body = substr($body, $start);

$end = strpos($body, '</Service>');

$services[] = substr($body, 0, $end+10);

$body = substr($body, $end+9);

} else {

break;

}

}

$allowed_types = array();

foreach( explode(", ", constant('MODULE_SHIPPING_USPS_TYPES_INTL_' . $vendors_id)) as $value ) $allowed_types[$value] = $this->intl_types[$value];

 

$size = sizeof($services);

for ($i=0, $n=$size; $i<$n; $i++) {

if (strpos($services[$i], '<Postage>')) {

$service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);

$service = $regs[1];

$postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);

$postage = $regs[1];

$time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs);

$time = $tregs[1];

$time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);

$time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);

$time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);

 

if( !in_array($service, $allowed_types) ) continue;

if (isset($this->service) && ($service != $this->service) ) {

continue;

}

 

$rates[] = array($service => $postage);

if ($time != '') $transittime[$service] = ' (' . $time . ')';

}

}

}

}

 

return ((sizeof($rates) > 0) ? $rates : false);

}

 

function country_list() {

$list = array('AF' => 'Afghanistan',

'AL' => 'Albania',

'DZ' => 'Algeria',

'AD' => 'Andorra',

'AO' => 'Angola',

'AI' => 'Anguilla',

'AG' => 'Antigua and Barbuda',

'AR' => 'Argentina',

'AM' => 'Armenia',

'AW' => 'Aruba',

'AU' => 'Australia',

'AT' => 'Austria',

'AZ' => 'Azerbaijan',

'BS' => 'Bahamas',

'BH' => 'Bahrain',

'BD' => 'Bangladesh',

'BB' => 'Barbados',

'BY' => 'Belarus',

'BE' => 'Belgium',

'BZ' => 'Belize',

'BJ' => 'Benin',

'BM' => 'Bermuda',

'BT' => 'Bhutan',

'BO' => 'Bolivia',

'BA' => 'Bosnia-Herzegovina',

'BW' => 'Botswana',

'BR' => 'Brazil',

'VG' => 'British Virgin Islands',

'BN' => 'Brunei Darussalam',

'BG' => 'Bulgaria',

'BF' => 'Burkina Faso',

'MM' => 'Burma',

'BI' => 'Burundi',

'KH' => 'Cambodia',

'CM' => 'Cameroon',

'CA' => 'Canada',

'CV' => 'Cape Verde',

'KY' => 'Cayman Islands',

'CF' => 'Central African Republic',

'TD' => 'Chad',

'CL' => 'Chile',

'CN' => 'China',

'CX' => 'Christmas Island (Australia)',

'CC' => 'Cocos Island (Australia)',

'CO' => 'Colombia',

'KM' => 'Comoros',

'CG' => 'Congo (Brazzaville),Republic of the',

'ZR' => 'Congo, Democratic Republic of the',

'CK' => 'Cook Islands (New Zealand)',

'CR' => 'Costa Rica',

'CI' => 'Cote d\'Ivoire (Ivory Coast)',

'HR' => 'Croatia',

'CU' => 'Cuba',

'CY' => 'Cyprus',

'CZ' => 'Czech Republic',

'DK' => 'Denmark',

'DJ' => 'Djibouti',

'DM' => 'Dominica',

'DO' => 'Dominican Republic',

'TP' => 'East Timor (Indonesia)',

'EC' => 'Ecuador',

'EG' => 'Egypt',

'SV' => 'El Salvador',

'GQ' => 'Equatorial Guinea',

'ER' => 'Eritrea',

'EE' => 'Estonia',

'ET' => 'Ethiopia',

'FK' => 'Falkland Islands',

'FO' => 'Faroe Islands',

'FJ' => 'Fiji',

'FI' => 'Finland',

'FR' => 'France',

'GF' => 'French Guiana',

'PF' => 'French Polynesia',

'GA' => 'Gabon',

'GM' => 'Gambia',

'GE' => 'Georgia, Republic of',

'DE' => 'Germany',

'GH' => 'Ghana',

'GI' => 'Gibraltar',

'GB' => 'Great Britain and Northern Ireland',

'GR' => 'Greece',

'GL' => 'Greenland',

'GD' => 'Grenada',

'GP' => 'Guadeloupe',

'GT' => 'Guatemala',

'GN' => 'Guinea',

'GW' => 'Guinea-Bissau',

'GY' => 'Guyana',

'HT' => 'Haiti',

'HN' => 'Honduras',

'HK' => 'Hong Kong',

'HU' => 'Hungary',

'IS' => 'Iceland',

'IN' => 'India',

'ID' => 'Indonesia',

'IR' => 'Iran',

'IQ' => 'Iraq',

'IE' => 'Ireland',

'IL' => 'Israel',

'IT' => 'Italy',

'JM' => 'Jamaica',

'JP' => 'Japan',

'JO' => 'Jordan',

'KZ' => 'Kazakhstan',

'KE' => 'Kenya',

'KI' => 'Kiribati',

'KW' => 'Kuwait',

'KG' => 'Kyrgyzstan',

'LA' => 'Laos',

'LV' => 'Latvia',

'LB' => 'Lebanon',

'LS' => 'Lesotho',

'LR' => 'Liberia',

'LY' => 'Libya',

'LI' => 'Liechtenstein',

'LT' => 'Lithuania',

'LU' => 'Luxembourg',

'MO' => 'Macao',

'MK' => 'Macedonia, Republic of',

'MG' => 'Madagascar',

'MW' => 'Malawi',

'MY' => 'Malaysia',

'MV' => 'Maldives',

'ML' => 'Mali',

'MT' => 'Malta',

'MQ' => 'Martinique',

'MR' => 'Mauritania',

'MU' => 'Mauritius',

'YT' => 'Mayotte (France)',

'MX' => 'Mexico',

'MD' => 'Moldova',

'MC' => 'Monaco (France)',

'MN' => 'Mongolia',

'MS' => 'Montserrat',

'MA' => 'Morocco',

'MZ' => 'Mozambique',

'NA' => 'Namibia',

'NR' => 'Nauru',

'NP' => 'Nepal',

'NL' => 'Netherlands',

'AN' => 'Netherlands Antilles',

'NC' => 'New Caledonia',

'NZ' => 'New Zealand',

'NI' => 'Nicaragua',

'NE' => 'Niger',

'NG' => 'Nigeria',

'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',

'NO' => 'Norway',

'OM' => 'Oman',

'PK' => 'Pakistan',

'PA' => 'Panama',

'PG' => 'Papua New Guinea',

'PY' => 'Paraguay',

'PE' => 'Peru',

'PH' => 'Philippines',

'PN' => 'Pitcairn Island',

'PL' => 'Poland',

'PT' => 'Portugal',

'QA' => 'Qatar',

'RE' => 'Reunion',

'RO' => 'Romania',

'RU' => 'Russia',

'RW' => 'Rwanda',

'SH' => 'Saint Helena',

'KN' => 'Saint Kitts (St. Christopher and Nevis)',

'LC' => 'Saint Lucia',

'PM' => 'Saint Pierre and Miquelon',

'VC' => 'Saint Vincent and the Grenadines',

'SM' => 'San Marino',

'ST' => 'Sao Tome and Principe',

'SA' => 'Saudi Arabia',

'SN' => 'Senegal',

'YU' => 'Serbia-Montenegro',

'SC' => 'Seychelles',

'SL' => 'Sierra Leone',

'SG' => 'Singapore',

'SK' => 'Slovak Republic',

'SI' => 'Slovenia',

'SB' => 'Solomon Islands',

'SO' => 'Somalia',

'ZA' => 'South Africa',

'GS' => 'South Georgia (Falkland Islands)',

'KR' => 'South Korea (Korea, Republic of)',

'ES' => 'Spain',

'LK' => 'Sri Lanka',

'SD' => 'Sudan',

'SR' => 'Suriname',

'SZ' => 'Swaziland',

'SE' => 'Sweden',

'CH' => 'Switzerland',

'SY' => 'Syrian Arab Republic',

'TW' => 'Taiwan',

'TJ' => 'Tajikistan',

'TZ' => 'Tanzania',

'TH' => 'Thailand',

'TG' => 'Togo',

'TK' => 'Tokelau (Union) Group (Western Samoa)',

'TO' => 'Tonga',

'TT' => 'Trinidad and Tobago',

'TN' => 'Tunisia',

'TR' => 'Turkey',

'TM' => 'Turkmenistan',

'TC' => 'Turks and Caicos Islands',

'TV' => 'Tuvalu',

'UG' => 'Uganda',

'UA' => 'Ukraine',

'AE' => 'United Arab Emirates',

'UY' => 'Uruguay',

'UZ' => 'Uzbekistan',

'VU' => 'Vanuatu',

'VA' => 'Vatican City',

'VE' => 'Venezuela',

'VN' => 'Vietnam',

'WF' => 'Wallis and Futuna Islands',

'WS' => 'Western Samoa',

'YE' => 'Yemen',

'ZM' => 'Zambia',

'ZW' => 'Zimbabwe');

 

return $list;

}

// Set up list of maximum allowed insurance values

 

function country_maxinsure() {

$list = array('AF' => 0,

'AL' => 0,

'DZ' => 2185,

'AD' => 5000,

'AO' => 0,

'AI' => 415,

'AG' => 60,

'AR' => 5000,

'AM' => 1350,

'AW' => 830,

'AU' => 3370,

'AT' => 5000,

'AZ' => 5000,

'BS' => 2795,

'BH' => 0,

'BD' => 5000,

'BB' => 220,

'BY' => 1323,

'BE' => 5000,

'BZ' => 1600,

'BJ' => 170,

'BM' => 440,

'BT' => 440,

'BO' => 0,

'BA' => 5000,

'BW' => 145,

'BR' => 5000,

'VG' => 165,

'BN' => 4405,

'BG' => 1030,

'BF' => 530,

'MM' => 4045,

'BI' => 790,

'KH' => 0,

'CM' => 5000,

'CA' => 675,

'CV' => 0,

'KY' => 0,

'CF' => 4405,

'TD' => 440,

'CL' => 0,

'CN' => 1130,

'CX' => 3370,

'CC' => 3370,

'CO' => 0,

'KM' => 690,

'CG' => 1685,

'ZR' => 0,

'CK' => 980,

'CR' => 0,

'CI' => 5000,

'HR' => 5000,

'CU' => 0,

'CY' => 5000,

'CZ' => 5000,

'DK' => 5000,

'DJ' => 880,

'DM' => 0,

'DO' => 0,

'TP' => 0,

'EC' => 0,

'EG' => 1685,

'SV' => 0,

'GQ' => 0,

'ER' => 0,

'EE' => 2020,

'ET' => 1000,

'FK' => 510,

'FO' => 5000,

'FJ' => 600,

'FI' => 5000,

'FR' => 5000,

'GF' => 5000,

'PF' => 1015,

'GA' => 485,

'GM' => 2575,

'GE' => 1350,

'DE' => 5000,

'GH' => 5000,

'GI' => 5000,

'GB' => 857,

'GR' => 5000,

'GL' => 5000,

'GD' => 350,

'GP' => 5000,

'GT' => 0,

'GN' => 875,

'GW' => 21,

'GY' => 10,

'HT' => 0,

'HN' => 0,

'HK' => 5000,

'HU' => 5000,

'IS' => 5000,

'IN' => 2265,

'ID' => 0,

'IR' => 0,

'IQ' => 0,

'IE' => 5000,

'IL' => 0,

'IT' => 5000,

'JM' => 0,

'JP' => 5000,

'JO' => 0,

'KZ' => 5000,

'KE' => 815,

'KI' => 0,

'KW' => 1765,

'KG' => 1350,

'LA' => 0,

'LV' => 1350,

'LB' => 440,

'LS' => 440,

'LR' => 440,

'LY' => 0,

'LI' => 5000,

'LT' => 5000,

'LU' => 5000,

'MO' => 4262,

'MK' => 2200,

'MG' => 675,

'MW' => 50,

'MY' => 1320,

'MV' => 0,

'ML' => 950,

'MT' => 5000,

'MQ' => 5000,

'MR' => 635,

'MU' => 270,

'YT' => 5000,

'MX' => 0,

'MD' => 1350,

'MC' => 5000,

'MN' => 440,

'MS' => 2200,

'MA' => 5000,

'MZ' => 0,

'NA' => 4405,

'NR' => 220,

'NP' => 0,

'NL' => 5000,

'AN' => 830,

'NC' => 1615,

'NZ' => 980,

'NI' => 440,

'NE' => 810,

'NG' => 205,

'KP' => 0,

'NO' => 0,

'OM' => 575,

'PK' => 270,

'PA' => 0,

'PG' => 445,

'PY' => 0,

'PE' => 0,

'PH' => 270,

'PN' => 0,

'PL' => 1350,

'PT' => 5000,

'QA' => 2515,

'RE' => 5000,

'RO' => 5000,

'RU' => 5000,

'RW' => 0,

'SH' => 170,

'KN' => 210,

'LC' => 400,

'PM' => 5000,

'VC' => 130,

'SM' => 5000,

'ST' => 440,

'SA' => 0,

'SN' => 865,

'YU' => 5000,

'SC' => 0,

'SL' => 0,

'SG' => 4580,

'SK' => 5000,

'SI' => 4400,

'SB' => 0,

'SO' => 440,

'ZA' => 1760,

'GS' => 510,

'KR' => 5000,

'ES' => 5000,

'LK' => 35,

'SD' => 0,

'SR' => 535,

'SZ' => 560,

'SE' => 5000,

'CH' => 5000,

'SY' => 3080,

'TW' => 1350,

'TJ' => 1350,

'TZ' => 230,

'TH' => 1350,

'TG' => 2190,

'TK' => 295,

'TO' => 515,

'TT' => 930,

'TN' => 2200,

'TR' => 880,

'TM' => 675,

'TC' => 0,

'TV' => 4715,

'UG' => 0,

'UA' => 5000,

'AE' => 5000,

'UY' => 0,

'UZ' => 5000,

'VU' => 0,

'VA' => 5000,

'VE' => 0,

'VN' => 0,

'WF' => 1615,

'WS' => 295,

'YE' => 0,

'ZM' => 540,

'ZW' => 600,

'US' => 5000);

 

return $list;

}

}

?>

 

I did a couple of changes to the file

Edited by drillsar
Link to comment
Share on other sites

OK. Sort order fix...

 

Replace this...

	function sort_order($vendors_id='1') {
  if (defined (@constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id))) {
	$this->sort_order = @constant('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);
  } else {
	$this->sort_order = '0';
  }
  return $this->sort_order;
}

With this...

	function sort_order($vendors_id='1') {
 $sort_order = constant ('MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id);
 if (isset ($sort_order)) {		$this->sort_order = $sort_order;
  } else {
	$this->sort_order = '0';
  }
  return $this->sort_order;
}

 

Drillsar,

 

I didn't modify my catalog/admin/includes/functions/general.php because I have the "tep_cfg_select_multioption" configured elsewhere.

 

Rick

 

Where is this code Rick?

 

I think I figured out I missed something in my file:

 

I added this I forgot to add the insurance parts:

 

function keys($vendors_id) {

return array('MODULE_SHIPPING_USPS_STATUS_' . $vendors_id, 'MODULE_SHIPPING_USPS_USERID_' . $vendors_id, 'MODULE_SHIPPING_USPS_PASSWORD_' . $vendors_id, 'MODULE_SHIPPING_USPS_SERVER_' . $vendors_id, 'MODULE_SHIPPING_USPS_HANDLING_' . $vendors_id, 'MODULE_SHIPPING_USPS_TAX_CLASS_' . $vendors_id, 'MODULE_SHIPPING_USPS_ZONE_' . $vendors_id, 'MODULE_SHIPPING_USPS_SORT_ORDER_' . $vendors_id, 'MODULE_SHIPPING_USPS_OPTIONS_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_' . $vendors_id, 'MODULE_SHIPPING_USPS_TYPES_INTL_' . $vendors_id, 'MODULE_SHIPPING_USPS_INS1_'. $vendors_id, 'MODULE_SHIPPING_USPS_INS2_' . $vendors_id, 'MODULE_SHIPPING_USPS_INS3_' . $vendors_id, 'MODULE_SHIPPING_USPS_INS4_' . $vendors_id, 'MODULE_SHIPPING_USPS_INS5_' . $vendors_id, 'MODULE_SHIPPING_USPS_INS6_' . $vendors_id, 'MODULE_SHIPPING_USPS_INSURE_' . $vendors_id, 'MODULE_SHIPPING_USPS_INSURE_TAX_' . $vendors_id);

}

Link to comment
Share on other sites

Jim,

 

The fix for Sort Order came from an older MVS USPS module. I think from the original module I worked on with you and Craig a couple of years ago. I just stole it. I've added @ in front of the constant and it seems to work. I'm also not seeing an error with other vendors that don't have the module installed, but I'll keep on testing before I put this on my live store. Also, I would really like to get the insurance code working.

 

Thanks,

Rick

I remember that code from somewhere. I also remember not being very happy with it. I suspect that's because I don't understand why it works and the other one doesn't. That sort of thing bugs me.

 

I still don't see anything wrong with the Insurance code. If you want, email me a copy of your usps.php and I'll take a look at it. I usually need to poke at these things a bit to figure out what's going on.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

I just sent you my usps.php file

 

im also now getting a error:

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/html/catalog/includes/modules/vendors_shipping/usps.php on line 222

Drillsar,

 

Take a look at steps 1 and 2 in the trouble shooting section of the installation text. It fixes the problem you have here.

 

Why did you comment out tep_cfg_select_multioption? Did you get a specific error?

 

Rick

Link to comment
Share on other sites

I see where to change the code to yes to start the debug but how do you actually get the data thats being passed?

 

Thanks again

Pete

 

I was able to set the debug to yes and comment out the white text so it would be black and I could read it. However - same problem. It works great when not logged in but when I am logged in it never gets to a point to even show the debug data - at most I get a white background then the IE7 error page...

 

any help is greatly appreciated!!

 

Pete

Link to comment
Share on other sites

Jim,

 

The fix for Sort Order came from an older MVS USPS module. I think from the original module I worked on with you and Craig a couple of years ago. I just stole it. I've added @ in front of the constant and it seems to work. I'm also not seeing an error with other vendors that don't have the module installed, but I'll keep on testing before I put this on my live store. Also, I would really like to get the insurance code working.

 

Thanks,

Rick

I can't get USPS working -- I think I have the wrong password, and I can't find anything else. I have a couple of changes for you to try though. Change Line 177 to:

if (($maxins == 0) || (constant('MODULE_SHIPPING_USPS_INSURE_' . $vendors_id) == 'False')) {

and change Line 227 to:

	  $uspsQuote = $this->_getQuote ($vendors_id);

Please let me know if this does any good.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

I can't get USPS working -- I think I have the wrong password, and I can't find anything else. I have a couple of changes for you to try though. Change Line 177 to:
if (($maxins == 0) || (constant('MODULE_SHIPPING_USPS_INSURE_' . $vendors_id) == 'False')) {

and change Line 227 to:

	  $uspsQuote = $this->_getQuote ($vendors_id);

Please let me know if this does any good.

 

Regards

Jim

Jim,

 

I had found the typo on line 177 I guess after I had sent you the code, That did get rid of the last 2 error messages. I've added $vendors_id to line 227, but that didn't seem to have much effect. The problem has to be right in that area and I think it has to do with this block of code...

if (($maxins == 0) || (constant('MODULE_SHIPPING_USPS_INSURE_' . $vendors_id) == 'False')) {
 $insurance = 0; }

// US and Canada share the same insurance calculation (though not the same maximum)

else if (($order->delivery['country']['iso_code_2'] == 'US') || ($order->delivery['country']['iso_code_2'] == 'CA')){
if ($costperpkg<=50) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS1_' . $vendors_id);}
else if ($costperpkg<=100) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS2_' . $vendors_id);}
	else if ($costperpkg<=200) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS3_' . $vendors_id);}
	else if ($costperpkg<=300) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS4_' . $vendors_id);}
else {
	$insurance = constant('MODULE_SHIPPING_USPS_INS4_' . $vendors_id) + ((ceil($costperpkg/100) -3) * constant('MODULE_SHIPPING_USPS_INS5_' . $vendors_id)); }
 }

// if insurance allowed and is not US or Canada then calculate international insurance

else {
if ($costperpkg<=50) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS6_' . $vendors_id);}
else if ($costperpkg<=100) {
	$insurance=constant('MODULE_SHIPPING_USPS_INS7_' . $vendors_id);}
else {
	$insurance = constant('MODULE_SHIPPING_USPS_INS7_' . $vendors_id) + ((ceil($costperpkg/100) - 1) * constant('MODULE_SHIPPING_USPS_INS8_' . $vendors_id)); }
}

I think the calculations aren't working because of the "MODULE_SHIPPING_USPS_INS1" through "MODULE_SHIPPING_USPS_INS8" constants. I don't know how to define them because they all =$insrance, not $insurance1, etc. Does that make sense? Or am I way off base.

 

Thanks, Rick

Link to comment
Share on other sites

Jim,

 

I had found the typo on line 177 I guess after I had sent you the code, That did get rid of the last 2 error messages. I've added $vendors_id to line 227, but that didn't seem to have much effect. The problem has to be right in that area and I think it has to do with this block of code...<code snipped>I think the calculations aren't working because of the "MODULE_SHIPPING_USPS_INS1" through "MODULE_SHIPPING_USPS_INS8" constants. I don't know how to define them because they all =$insrance, not $insurance1, etc. Does that make sense? Or am I way off base.

 

Thanks, Rick

That code is a clumsy way of doing it, but it should work. The idea is to set $insurance to a value dependent on $costperpkg and the constant related to that cost. My code validator isn't throwing any errors, and there's nothing else I can see in that area that looks dodgy. All of the variables appear to be getting set. Time to start snooping some of those values, I guess.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

I put some test numbers into this, and I'm seeing the Insurance being added to the shipping cost. I have no idea why yours isn't. I can only suggest you put some Print statements in (or file logging or mail if you are on a live site) and try to find the values that are not properly set.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

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...