Dr_killer_UK Posted March 12, 2011 Share Posted March 12, 2011 (edited) I used to sell from the UK and the website was setup fine for Royal Mail but now I'm selling from the USA so the website is going to USPS. I have implemented USPS fine. I just have a few tweaks to make and am a bit stuck on this tweak. I do not like shipping any value just plain 1st class international as you can't add insurance to it. The USPS module will already add insurance to priority mail though so what i wanted to do was to have the 1st class international not show up after say $20 value. Please note I do need 1st class international as an option (up to the value i want) as many of the items i sell are sub $5 price range. Thanks for your time whoever replies. Johnathan Below is my current USPS.php <?php /* $Id: usps.php 5.0 2008-03-01 04:59:07Z user $ +++++ Original contribution by Brad Waite and Fritz Clapp ++++ ++++ Revisions and Modifications made by Greg Deeth, 2008 ++++ ++++++++++++ Insurance module by Kevin Shelton +++++++++++++++ Copyright 2008 osCommerce Released under the GNU General Public License */ //VERSION: 5.0.3 ALPHA //UPDATED: January 6th, 2011 by Fulluv Scents //LAST UPDATED January 6th, 2011 by a HUGE collaberation of minds - // Fulluv Scents, altoid, pbolyn, wkdwich and more.. //Please refer to http://www.usps.com/webtools/ for more information on API syntax. class usps { var $code, $title, $description, $icon, $enabled, $countries; function usps() { global $order; $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->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->handling = explode( ", ", MODULE_SHIPPING_USPS_HANDLING_DOMESTIC); $this->types = array( 'Express Mail' => 'Express Mail', 'Express Mail Flat Rate Envelope' => 'Express Mail Flat Rate Envelope', 'Priority Mail' => 'Priority Mail', 'Priority Mail Flat Rate Envelope' => 'Priority Mail Flat Rate Envelope', 'Priority Mail Small Flat Rate Box' => 'Priority Mail Small Flat Rate Box', 'Priority Mail Medium Flat Rate Box' => 'Priority Mail Medium Flat Rate Box', 'Priority Mail Large Flat Rate Box' => 'Priority Mail Large Flat Rate Box', 'Parcel Post' => 'Parcel Post', 'First-Class Mail' => 'First-Class Mail', 'Media Mail' => 'Media Mail' ); $this->intl_types = array( 'Global Express' => 'Global Express Guaranteed (GXG)**', 'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular', 'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular', 'USPS GXG Envelopes' => 'USPS GXG Envelopes**', 'Express Mail Int' => 'Express Mail International', 'Express Mail Int Flat Rate Env' => 'Express Mail International Flat Rate Envelope', 'Priority Mail International' => 'Priority Mail International', 'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail International Large Flat Rate Box', 'Priority Mail Int Flat Rate Med Box' => 'Priority Mail International Medium Flat Rate Box', 'Priority Mail Int Flat Rate Small Box' => 'Priority Mail International Small Flat Rate Box**', 'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope**', 'First-Class Mail Int Lrg Env' => 'First-Class Mail International Large Envelope**', 'First-Class Mail Int Package' => 'First-Class Mail International Package**', 'First-Class Mail Int Letter' => 'First-Class Mail International Letter**' ); $this->countries = $this->country_list(); $this->countryinsure = $this->country_maxinsure(); } function quote($method = '') { 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); } if (MODULE_SHIPPING_USPS_INSURE_TAX == 'True') { $costperpkg = $order->info['total'] / $shipping_num_boxes; } else { $costperpkg = $order->info['subtotal'] / $shipping_num_boxes; } $maxins = $this->countryinsure[$order->delivery['country']['iso_code_2']]; if ($costperpkg > $maxins) $costperpkg = $maxins; if (($maxins == 0) || (MODULE_SHIPPING_USPS_INSURE == 'False')) { $insurance = 0; } else if (($order->delivery['country']['iso_code_2'] == 'US')){ if ($costperpkg<=17) { $insurance=MODULE_SHIPPING_USPS_INS1; } else if ($costperpkg<=100) { $insurance=MODULE_SHIPPING_USPS_INS2; } else if ($costperpkg<=200) { $insurance=MODULE_SHIPPING_USPS_INS3; } else if ($costperpkg<=300) { $insurance=MODULE_SHIPPING_USPS_INS4; } else { $insurance = MODULE_SHIPPING_USPS_INS4 + ((ceil($costperpkg/100) -3) * MODULE_SHIPPING_USPS_INS5); } } else { if ($costperpkg<=50) { $insurance=MODULE_SHIPPING_USPS_INS6; } else if ($costperpkg<=100) { $insurance=MODULE_SHIPPING_USPS_INS7; } else if ($costperpkg<=200) { $insurance=MODULE_SHIPPING_USPS_INS8; } else if ($costperpkg<=300) { $insurance=MODULE_SHIPPING_USPS_INS9; } else { $insurance = MODULE_SHIPPING_USPS_INS9 + ((ceil($costperpkg/100) - 3) * MODULE_SHIPPING_USPS_INS10); } } if ($shipping_weight <= 0) {$shipping_weight = 0;} $shipping_weight = ($shipping_weight < 0.0625 ? 0.0625 : $shipping_weight); $shipping_pounds = floor ($shipping_weight); $shipping_ounces = tep_round_up((16 * ($shipping_weight - floor($shipping_weight))), 2); $this->_setWeight($shipping_pounds, $shipping_ounces, $shipping_weight); if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { $shiptitle = ' (' . $shipping_num_boxes . ' x ' . tep_round_up($shipping_weight, 2) . 'lbs)' . ' (' . $shipping_pounds . 'lbs, ' . $shipping_ounces . 'oz)'; } else { $shiptitle = ''; } $uspsQuote = $this->_getQuote(); if (is_array($uspsQuote)) { if (isset($uspsQuote['error'])) { $this->quotes = array('module' => $this->title, 'error' => $uspsQuote['error']); } else { $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(', ', MODULE_SHIPPING_USPS_OPTIONS))) $title .= $transittime[$type]; if (MODULE_SHIPPING_DMSTC_INSURANCE_OPTION == 'Force Insurance') { $methods[] = array('id' => $type, 'title' => $title, 'cost' => ($cost + $insurance + $handling_cost[0]) * $shipping_num_boxes); } else { $methods[] = array('id' => $type, 'title' => $title, 'cost' => ($cost + $handling_cost[0]) * $shipping_num_boxes); } } $this->quotes['methods'] = $methods; if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $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; } function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } 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 USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS 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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', '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_USPS_ZONE', '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())"); 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', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '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 ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '0', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ', 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 ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'tep_cfg_select_option(array(\'test\', \'production\'), ', 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 ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE, NONE', 'Enter the USPS USERID assigned to you. <u>You must contact USPS to have them switch you to the Production server.</u> Otherwise this module will not work!', '6', '0', 'tep_cfg_multiinput_list(array(\'ID\', \'Password\'), ', 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 ('Domestic Handling Fees', 'MODULE_SHIPPING_USPS_HANDLING_DOMESTIC', '0, 0, 0, 0, 0, 0, 0, 0, 0, 0', 'Add a different handling fee for each shipping type.', '6', '0', 'tep_cfg_multiinput_list(array(\'Express Mail\', \'Express Mail Flat Rate Envelope\', \'Priority Mail\', \'Priority Mail Flat Rate Envelope\', \'Priority Mail Small Flat Rate Box\', \'Priority Mail Medium Flat Rate Box\', \'Priority Mail Large Flat Rate Box\', \'First-Class Mail\', \'Parcel Post\',\'Media Mail\'), ', 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 ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'Express Mail, Express Mail Flat Rate Envelope, Priority Mail, Priority Mail Flat Rate Envelope, Priority Mail Small Flat Rate Box, Priority Mail Medium Flat Rate Box, Priority Mail Large Flat Rate Box, Parcel Post, First-Class Mail, Media Mail', 'Select the domestic services to be offered:', '6', '0', 'tep_cfg_select_multioption(array(\'Express Mail\', \'Express Mail Flat Rate Envelope\', \'Priority Mail\', \'Priority Mail Flat Rate Envelope\', \'Priority Mail Small Flat Rate Box\', \'Priority Mail Medium Flat Rate Box\', \'Priority Mail Large Flat Rate Box\', \'Parcel Post\', \'First-Class Mail\',\'Media Mail\'), ', 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 ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, USPS GXG Envelopes, Express Mail Int, Express Mail Int Flat Rate Env, Priority Mail International, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Small Box, Priority Mail Int Flat Rate Med Box, Priority Mail Int Flat Rate Lrg Box, First-Class Mail Int Lrg Env, First-Class Mail Int Package, First-Class Mail Int Letter', 'Select the international services to be offered:', '6', '0', 'tep_cfg_select_multioption( array(\'Global Express\', \'Global Express Non-Doc Rect\', \'Global Express Non-Doc Non-Rect\', \'USPS GXG Envelopes\', \'Express Mail Int\', \'Express Mail Int Flat Rate Env\', \'Priority Mail International\', \'Priority Mail Int Flat Rate Env\', \'Priority Mail Int Flat Rate Small Box\', \'Priority Mail Int Flat Rate Med Box\', \'Priority Mail Int Flat Rate Lrg Box\', \'First-Class Mail Int Lrg Env\', \'First-Class Mail Int Package\', \'First-Class Mail Int Letter\'), ', 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 ('Domstic First-Class Threshold', 'MODULE_SHIPPING_CONFIG_DMSTC_FIRSTCLASS_THRESHOLD', '0, 3.5, 3.5, 10, 10, 13, 0, 13', 'If the total weight is between 0oz and 3.5oz, Letter is used. Over 3.5oz, Flat is used, etc. ONLY ONE TYPE WILL SHOW IN CART<br><br><u>Maximums:</u><br>Letters <u><</u> 3.5oz<br>Flats (large envelopes) <u><</u> 13oz<br>Parcels (packages) <u><</u> 13oz</i>', '6', '0', 'tep_cfg_multiinput_duallist_oz(array(\'Letter\', \'Flat\', \'Parcel\', \'MACHINABLE True\'), ', 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 ('Domstic Priority Mail Threshold', 'MODULE_SHIPPING_CONFIG_DMSTC_PRIORITY_THRESHOLD', '0, 70, 0, 70, 0, 70, 0, 70, 0, 70', 'If the total weight is between 0lb and 2lbs, Standard is used. Between 1lb and 3lbs, Flat Rate is used, etc. CAN BE SHOWN SIMULTANEOUSLY<br><br><i>All Priority types have a weight limit of 70lbs.</i>', '6', '0', 'tep_cfg_multiinput_duallist_lb(array(\'Flat Rate Envelope\', \'Sm Flat Rate Box\', \'Md Flat Rate Box\', \'Lg Flat Rate Box\', \'Standard Priority\'), ', 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 ('Domstic Other Mail Threshold', 'MODULE_SHIPPING_CONFIG_DMSTC_OTHER_THRESHOLD', '0, 70, 0, 70, 0, 30, 30, 50, 50, 70, 0, 70', 'ParcelPst Reg, Lrg, OvrSz cannot be used simultaneously. All others are controlled separately.<br><br><i>USPS limit is 70lbs</i>', '6', '0', 'tep_cfg_multiinput_duallist_lb(array(\'Express FltRt Env\', \'Express Standard\', \'Parcel Pst Reg\', \'Parcel Pst Lrg\', \'Parcel Pst OvrSz\', \'Media Mail\'), ', 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 ('Domestic Insurance Options', 'MODULE_SHIPPING_DMSTC_INSURANCE_OPTION', 'None', 'Select how you want to offer USPS Domestic Insurance.', '6', '0', 'tep_cfg_select_option(array(\'None\', \'Buyers Option Does not work yet\', \'Force Insurance\'), ', 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 ('International Insurance Options', 'MODULE_SHIPPING_INTL_INSURANCE_OPTION', 'None', 'Select how you want to offer USPS International Insurance. International Insurance is calculated automatically by USPS for certain mailing types.', '6', '0', 'tep_cfg_select_option(array(\'None\', \'Buyers Option Does not work yet\', \'Force Insurance\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('US $.01-$17.00', 'MODULE_SHIPPING_USPS_INS1', '1.75', 'US insurance for totals $.01-$17.00', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('US $17.01-$100.00', 'MODULE_SHIPPING_USPS_INS2', '2.25', 'US insurance for totals $17.01-$100', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('US $100.01-$200.00', 'MODULE_SHIPPING_USPS_INS3', '2.75', 'US insurance for totals $100.01-$200', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('US $200.01-$300.00', 'MODULE_SHIPPING_USPS_INS4', '4.70', 'US insurance for totals $200.01-$300', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('US per $100 over $300', 'MODULE_SHIPPING_USPS_INS5', '1.00', 'US insurance for every $100 over $300 (add)', '6', '0', 'currencies->format', 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() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_HANDLING_DOMESTIC', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_DMSTC_INSURANCE_OPTION', 'MODULE_SHIPPING_INTL_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_CONFIG_DMSTC_FIRSTCLASS_THRESHOLD', 'MODULE_SHIPPING_CONFIG_DMSTC_PRIORITY_THRESHOLD', 'MODULE_SHIPPING_CONFIG_DMSTC_OTHER_THRESHOLD', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', /*'MODULE_SHIPPING_USPS_INS6', 'MODULE_SHIPPING_USPS_INS7', 'MODULE_SHIPPING_USPS_INS8', 'MODULE_SHIPPING_USPS_INS9', 'MODULE_SHIPPING_USPS_INS10', 'MODULE_SHIPPING_USPS_INSURE', */'MODULE_SHIPPING_USPS_INSURE_TAX'); } function _setService($service) { $this->service = $service; } function _setWeight($pounds, $ounces=0, $weight) { $this->pounds = $pounds; $this->ounces = $ounces; $this->weight = $weight; } function _setMachinable($machinable) { $this->machinable = $machinable; } function _getQuote() { global $order, $transittime; $transit = (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))); $Authentication = explode( ", ", MODULE_SHIPPING_USPS_USERID); //0=>USERID, 1=>PASSWORD if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { $request = '<RateV3Request USERID="' . $Authentication[0] . '" PASSWORD="' . $Authentication[1] . '">'; $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(", ", MODULE_SHIPPING_USPS_TYPES); while (list($key, $value) = each($this->types)) { if ( !in_array($key, $allowed_types) ) continue; if ($key == 'First-Class Mail'){ $FCT = explode(", ", MODULE_SHIPPING_CONFIG_DMSTC_FIRSTCLASS_THRESHOLD); if($this->pounds == 0) { if($FCT[0] < $this->ounces && $this->ounces <= $FCT[1]) { $this->FirstClassMailType = 'LETTER'; } else if($FCT[2] < $this->ounces && $this->ounces <= $FCT[3]) { $this->FirstClassMailType = 'FLAT'; } else if($FCT[4] < $this->ounces && $this->ounces <= $FCT[5]) { $this->FirstClassMailType = 'PARCEL'; } else { $key = 'none'; } if($FCT[6] < $this->ounces && $this->ounces <= $FCT[7]) { $this->machinable = 'true'; } else { $this->machinable = 'false'; } } } $PT = explode(", ", MODULE_SHIPPING_CONFIG_DMSTC_PRIORITY_THRESHOLD); if ($key == 'Priority Mail'){ if ($PT[8] < $this->weight && $this->weight <= $PT[9]) { $this->container = ''; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail Flat Rate Envelope'){ if ($PT[0] < $this->weight && $this->weight <= $PT[1]) { $key = 'Priority'; //DO NOT CHANGE $this->container = 'FLAT RATE ENVELOPE'; $this->size = ''; } else { $key = 'none'; } } if ($key == 'Priority Mail Small Flat Rate Box'){ if ($PT[2] < $this->weight && $this->weight <= $PT[3]) { $key = 'Priority'; //DO NOT CHANGE $this->container = 'SM FLAT RATE BOX'; $this->size = ''; } else { $key = 'none'; } } if ($key == 'Priority Mail Medium Flat Rate Box'){ if ($PT[4] < $this->weight && $this->weight <= $PT[5]) { $key = 'Priority'; //DO NOT CHANGE $this->container = 'MD FLAT RATE BOX'; $this->size = ''; } else { $key = 'none'; } } if ($key == 'Priority Mail Large Flat Rate Box'){ if ($PT[6] < $this->weight && $this->weight <= $PT[7]) { $key = 'Priority'; //DO NOT CHANGE $this->container = 'LG FLAT RATE BOX'; $this->size = ''; } else { $key = 'none'; } } $AOT = explode( ", ", MODULE_SHIPPING_CONFIG_DMSTC_OTHER_THRESHOLD); if ($key == 'Express Mail'){ if ($PT[2] < $this->weight && $this->weight <= $PT[3]) { $this->container = ''; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Express Mail Flat Rate Envelope'){ if ($PT[0] < $this->weight && $this->weight <= $PT[1]) { $key = 'Express'; //DO NOT CHANGE $this->container = 'FLAT RATE ENVELOPE'; $this->size = ''; } else { $key = 'none'; } } if ($key == 'Parcel Post'){ //WEIGHT THRESHOLD OPTIONS (DEFAULT MACHINABLE: WEIGHT<70lbs WEIGHT CANNOT EXCEED 70lbs ANYWAY) if ($AOT[4] < $this->weight && $this->weight <= $AOT[5]){ $this->machinable = 'true'; //OPTIONS: 'true', 'false' $this->size = 'REGULAR'; } elseif ($AOT[6] < $this->weight && $this->weight <= $AOT[7]){ $this->machinable = 'true'; //OPTIONS: 'true', 'false' $this->size = 'LARGE'; } elseif ($AOT[8] < $this->weight && $this->weight <= $AOT[9]){ $this->machinable = 'true'; //OPTIONS: 'true', 'false' $this->size = 'OVERSIZE'; } else { $key = 'none'; } } if ($key == 'Media Mail'){ if ($AOT[10] < $this->weight && $this->weight <= $AOT[11]){ $this->size = 'REGULAR'; //OPTIONS: 'REGULAR, 'LARGE' } else { $key = 'none'; } } $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<FirstClassMailType>' . $this->FirstClassMailType . '</FirstClassMailType>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</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="' . $Authentication[0] . '" PASSWORD="' . $Authentication[1] . '">' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>'; switch ($key) { case 'Express Mail': $transreq[$key] = 'API=ExpressMail&XML=' . urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>'); if ($this->container == 'FLAT RATE ENVELOPE') { $key = 'Express Mail Flat Rate Envelope'; } break; case 'Priority Mail': $transreq[$key] = 'API=PriorityMail&XML=' . urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); if ($this->container == 'FLAT RATE ENVELOPE') { $key = 'Priority Mail Flat Rate Envelope'; } elseif ($this->container == 'SM FLAT RATE BOX') { $key = 'Priority Mail Small Flat Rate Box'; } elseif ($this->container == 'MD FLAT RATE BOX') { $key = 'Priority Mail Medium Flat Rate Box'; } elseif ($this->container == 'LG FLAT RATE BOX') { $key = 'Priority Mail Large Flat Rate Box'; } break; case 'Parcel Post': $transreq[$key] = 'API=StandardB&XML=' . urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; default: $transreq[$key] = ''; break; } } $services_count++; } $request .= '</RateV3Request>'; //'</RateRequest>'; //Changed by Greg Deeth April 30, 2008 $request = 'API=RateV3&XML=' . urlencode($request); } else { $request = '<IntlRateRequest USERID="' . $Authentication[0] . '" PASSWORD="' . $Authentication[1] . '">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<ValueOfContents>' . $order->info['total'] . '</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } switch (MODULE_SHIPPING_USPS_SERVER) { case 'production': $usps_server = 'production.shippingapis.com'; //'stg-production.shippingapis.com'; // or stg-secure.shippingapis.com //'production.shippingapis.com'; $api_dll = 'shippingapi.dll'; //'shippingapi.dll'; break; case 'test': default: $usps_server = 'testing.shippingapis.com'; $api_dll = 'ShippingAPITest.dll'; break; } $body = ''; if (!class_exists('httpClient')) { include('includes/classes/http_client.php'); } $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(); //mail('[email protected]','USPS rate quote response',$transresp[$key],'From: <[email protected]>'); } } $http->Disconnect(); } else { return false; } $body = str_replace('<sup>&reg;</sup>', '', $body); $body = str_replace('<sup>&trade;</sup>', '', $body); $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(); $rates_sorter = 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], '<Rate>')) { $service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs); if ( !function_exists('htmlspecialchars_decode') ) { function htmlspecialchars_decode($text) { return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); } } $service = htmlspecialchars_decode($regs[1]); $service = preg_replace('/\<sup\>\®\<\/sup\>/', '<sup>®</sup>', $service); $service = $regs[1]; $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs); $postage = $regs[1]; $insurance = ereg('<Insurance>(.*)</Insurance>', $response[$i], $regs); $insurance = $regs[1]; switch ($service) { case 'Express Mail': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_EXPRESS; } else { $time = MODULE_SHIPPING_USPS_TEXT_TOMORROW . $time; } $postage = $postage + $this->handling[0]; break; case 'Express Mail Flat Rate Envelope': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_EXPRESS; } else { $time = MODULE_SHIPPING_USPS_TEXT_TOMORROW . $time; } $postage = $postage + $this->handling[1]; break; case 'Priority Mail': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PRIORITY; } elseif ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[2]; break; case 'Priority Mail Flat Rate Envelope': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PRIORITY; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[3]; break; case 'Priority Mail Small Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PRIORITY; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[4]; break; case 'Priority Mail Medium Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PRIORITY; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[5]; break; case 'Priority Mail Large Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PRIORITY; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[6]; break; case 'Parcel Post': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = MODULE_SHIPPING_USPS_TEXT_PARCELPOST; } elseif ($time == '1') { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->handling[8]; break; case 'First-Class Mail': $time = MODULE_SHIPPING_USPS_TEXT_FIRSTCLASS; $postage = $postage + $this->handling[7]; break; case 'First-Class Mail Letter': $time = MODULE_SHIPPING_USPS_TEXT_FIRSTCLASS; $postage = $postage + $this->handling[7]; break; case 'First-Class Mail Large Envelope': $time = MODULE_SHIPPING_USPS_TEXT_FIRSTCLASS; $postage = $postage + $this->handling[7]; break; case 'First-Class Mail Package': $time = MODULE_SHIPPING_USPS_TEXT_FIRSTCLASS; $postage = $postage + $this->handling[7]; break; case 'Media Mail': $time = MODULE_SHIPPING_USPS_TEXT_MEDIA; $postage = $postage + $this->handling[9]; break; case 'Bound Printed Matter': $time = MODULE_SHIPPING_USPS_TEXT_PRIMTEDMATTER; $postage = $postage + $this->handling[9]; break; default: $time = ''; break; } $rates[] = array($service => $postage); $rates_sorter[] = $postage; if ($transit) { 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(", ", MODULE_SHIPPING_USPS_TYPES_INTL) 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); $time = ' (' . $time . ') '; if( !in_array($service, $allowed_types) ) continue; if (isset($this->service) && ($service != $this->service) ) { continue; } if (strpos($services[$i], '<Insurance>')) { $iinsurance = ereg('<Insurance>(.*)</Insurance>', $services[$i], $regs); $iinsurance = $regs[1]; if (MODULE_SHIPPING_INTL_INSURANCE_OPTION == 'Force Insurance') { $postage = $postage + $iinsurance; if ($iinsurance > 0) { $time = ($time . ' ~~' . MODULE_SHIPPING_USPS_TEXT_INSURED . ' $' . $order->info['total'] . '~~'); } } } $postage = $postage + $handling_cost[$i]; $rates[] = array($service => $postage); $rates_sorter[] = $postage; if ($time != '') $transittime[$service] = $time; } } } } print_r($handling_cost); asort($rates_sorter); $sorted_rates = array(); foreach (array_keys($rates_sorter) as $key){ $sorted_rates[] = $rates[$key]; } return ((sizeof($sorted_rates) > 0) ? $sorted_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; } 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; } } ?> Edited March 12, 2011 by Jan Zonjee code tags added Quote Link to comment Share on other sites More sharing options...
Guest Posted March 16, 2011 Share Posted March 16, 2011 Lucky you, I just happened to run across this post while googling something totally unrelated (I saw my name). First of all, the code you are using is outdated and it will collapse on you very soon when USPS changes to the V4 API in May. Try installing the code that was uploaded January 28, 2011. It is MUCH better. You can turn off the international shipping at a certain threshold if you like. I assume you mean ALL international, right? When you get the new code installed, post back and I'll get you a fix to set the threshold. Too late at night to put it together now. Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted March 20, 2011 Author Share Posted March 20, 2011 Lucky you, I just happened to run across this post while googling something totally unrelated (I saw my name). First of all, the code you are using is outdated and it will collapse on you very soon when USPS changes to the V4 API in May. Try installing the code that was uploaded January 28, 2011. It is MUCH better. You can turn off the international shipping at a certain threshold if you like. I assume you mean ALL international, right? When you get the new code installed, post back and I'll get you a fix to set the threshold. Too late at night to put it together now. Thanks for the reply. I had given up hope of any one replying and luckily just today thought i'd check lol. I updated it to the below USPS.PHP but this one doesn't have a box for the USPS webtools password when you try and configure it in admin (only the ID)? Also i was wanting to just cut out plain 1st class intentional not all international after say $20 cart value. That way it will only show priority international which insurance can be added onto thus keeping my self covered. <?php /* $Id: usps.php 5.2.1 +++++ Original contribution by Brad Waite and Fritz Clapp ++++ ++++ Revisions and Modifications made by Greg Deeth, 2008 ++++ Copyright 2008 osCommerce Released under the GNU General Public License //VERSION: 5.2.1 ALPHA //LAST UPDATED: January 23rd, 2011 by Fulluv Scents */ ///////////////////////////////////////// ////////// Sets up USPS Class /////////// ///////////////////////////////////////// class usps { ///////////////////////////////////////// ///////////// Sets Variables //////////// ///////////////////////////////////////// var $code, $title, $description, $icon, $enabled, $countries; function usps() { if ( !function_exists('htmlspecialchars_decode') ) { function htmlspecialchars_decode($text) { return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); } } global $order; $this->code = 'usps'; $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE; $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION; $this->icon = DIR_WS_ICONS . 'shipping_usps.gif'; $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->countries = $this->country_list(); $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER; $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS; $this->processing = MODULE_SHIPPING_USPS_PROCESSING; $this->dmstc_handling = explode( ", ", MODULE_SHIPPING_USPS_DMSTC_HANDLING); $this->intl_handling = explode( ", ", MODULE_SHIPPING_USPS_INTL_HANDLING); $this->sig_conf_thresh = MODULE_SHIPPING_USPS_SIG_THRESH; $this->types = array( 'First-Class Mail regimark' => 'First-Class Mail regimark', 'Media Mail regimark' => 'Media Mail regimark', 'Parcel Post regimark' => 'Parcel Post regimark', 'Priority Mail regimark' => 'Priority Mail regimark', 'Priority Mail regimark Flat Rate Envelope' => 'Priority Mail regimark Flat Rate Envelope', 'Priority Mail regimark Small Flat Rate Box' => 'Priority Mail regimark Small Flat Rate Box', 'Priority Mail regimark Medium Flat Rate Box' => 'Priority Mail regimark Medium Flat Rate Box', 'Priority Mail regimark Large Flat Rate Box' => 'Priority Mail regimark Large Flat Rate Box', 'Express Mail regimark' => 'Express Mail regimark', 'Express Mail regimark Flat Rate Envelope' => 'Express Mail regimark Flat Rate Envelope' ); $this->intl_types = array( 'Global Express' => 'Global Express Guaranteed regimark (GXG)**', 'Global Express Non-Doc Rect' => 'Global Express Guaranteed regimark Non-Document Rectangular', 'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed regimark Non-Document Non-Rectangular', 'USPS GXG Envelopes' => 'USPS GXG tradmrk Envelopes**', 'Express Mail Int' => 'Express Mail regimark International', 'Express Mail Int Flat Rate Env' => 'Express Mail regimark International Flat Rate Envelope', 'Priority Mail International' => 'Priority Mail regimark International', 'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail regimark International Large Flat Rate Box', 'Priority Mail Int Flat Rate Med Box' => 'Priority Mail regimark International Medium Flat Rate Box', 'Priority Mail Int Flat Rate Small Box' => 'Priority Mail regimark International Small Flat Rate Box**', 'Priority Mail Int Flat Rate Env' => 'Priority Mail regimark International Flat Rate Envelope**', 'First-Class Mail Int Lrg Env' => 'First-Class Mail regimark International Large Envelope**', 'First-Class Mail Int Package' => 'First-Class Mail regimark International Package**', 'First-Class Mail Int Letter' => 'First-Class Mail regimark International Letter**' ); } ///////////////////////////////////////// ///////////// Ends Variables //////////// ///////////////////////////////////////// ///////////////////////////////////////// /////////// Sets Country List /////////// ///////////////////////////////////////// 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; } ///////////////////////////////////////// /////////// Ends Country List /////////// ///////////////////////////////////////// ///////////////////////////////////////// ////////// Sets Quote /////////////////// ///////////////////////////////////////// function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes, $transittime, $dispinsure; if ( tep_not_null($method) && (in_array($method, $this->types) || in_array($method, $this->intl_types)) ) { $this->_setService($method); } if ($shipping_weight <= 0) {$shipping_weight = 0;} $shipping_weight = ($shipping_weight < 0.0625 ? 0.0625 : $shipping_weight); $shipping_pounds = floor ($shipping_weight); $shipping_ounces = tep_round_up((16 * ($shipping_weight - floor($shipping_weight))), 2); $this->_setWeight($shipping_pounds, $shipping_ounces, $shipping_weight); if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { $shiptitle = $shipping_pounds . ' lbs, ' . $shipping_ounces . ' oz'; } else { $shiptitle = ''; } $uspsQuote = $this->_getQuote(); if (is_array($uspsQuote)) { if (isset($uspsQuote['error'])) { $this->quotes = array('module' => $this->title, 'error' => $uspsQuote['error']); } else { $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); $title .= $transittime[$type] . $dispinsure[$type]; if (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True') { $methods[] = array('id' => $type, 'title' => $title, 'cost' => ($cost + $insurance + $handling_cost[0]) * $shipping_num_boxes); } else { $methods[] = array('id' => $type, 'title' => $title, 'cost' => ($cost + $handling_cost[0]) * $shipping_num_boxes); } } $this->quotes['methods'] = $methods; if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $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; } function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } ///////////////////////////////////////// ////////// Ends Quote /////////////////// ///////////////////////////////////////// ///////////////////////////////////////// //////////// Install Module ///////////// ///////////////////////////////////////// function install() { tep_db_query("ALTER TABLE `configuration` CHANGE `configuration_value` `configuration_value` TEXT NOT NULL, CHANGE `set_function` `set_function` TEXT NULL DEFAULT NULL"); 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 USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS 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 ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you. <u>You must contact USPS to have them switch you to the Production server.</u> Otherwise this module will not work!', '6', '3', 'tep_cfg_multiinput_list(array(\'\'), ', 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', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', 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_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', '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_USPS_ZONE', '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())"); 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 ('Display Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time, Display insurance', 'Select display options', '6', '0', 'tep_cfg_select_multioption(array(\'Display weight\', \'Display transit time\', \'Display insurance\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Processing Time', 'MODULE_SHIPPING_USPS_PROCESSING', '1', 'Days to Process Order', '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 ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_DMSTC_TYPES', 'First-Class Mail regimark, Media Mail regimark, Parcel Post regimark, Priority Mail regimark, Priority Mail regimark Flat Rate Envelope, Priority Mail regimark Small Flat Rate Box, Priority Mail regimark Medium Flat Rate Box, Priority Mail regimark Large Flat Rate Box, Express Mail regimark, Express Mail regimark Flat Rate Envelope', 'Select the domestic services to be offered:', '6', '4', 'tep_cfg_select_multioption(array(\'First-Class Mail regimark\', \'Media Mail regimark\', \'Parcel Post regimark\', \'Priority Mail regimark\', \'Priority Mail regimark Flat Rate Envelope\', \'Priority Mail regimark Small Flat Rate Box\', \'Priority Mail regimark Medium Flat Rate Box\', \'Priority Mail regimark Large Flat Rate Box\', \'Express Mail regimark\', \'Express Mail regimark Flat Rate Envelope\'), ', 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 ('Domestic Rates', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'Retail', 'Charge retail pricing or internet pricing?', '6', '0', 'tep_cfg_select_option(array(\'Retail\', \'Internet\'), ', 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 ('Domestic Delivery Confirmation', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'True', 'Automatically charge Delivery Confirmation for first class and parcel ($0.19)?', '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 ('Domestic Signature Confirmation', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'True', 'Automatically charge Signature Confirmation when available ($1.95)?', '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, date_added) values ('Signature Confirmation Threshold', 'MODULE_SHIPPING_USPS_SIG_THRESH', '100', 'Order total required before Signature Confirmation is triggered?', '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 ('Domestic Insurance Options', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'False', 'Force USPS Calculated Domestic Insurance?', '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 ('Domestic Handling Fees', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', '0, 0, 0, 0, 0, 0, 0, 0, 0, 0', 'Add a different handling fee for each shipping type.', '6', '0', 'tep_cfg_multiinput_list(array(\'First-Class\', \'Media\', \'Parcel\', \'Priority\', \'Priority Flat Env\', \'Priority Sm Flat Box\', \'Priority Med Flat Box\', \'Priority Lg Flat Box\', \'Express\', \'Express Flat Env\'), ', 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 ('Domestic First-Class Threshold', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', '0, 3.5, 3.5, 10, 10, 13', '<u>Maximums:</u><br>Letters 3.5oz<br>Large envelopes and parcels 13oz', '6', '0', 'tep_cfg_multiinput_duallist_oz(array(\'Letter\', \'Lg Env\', \'Package\'), ', 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 ('Domestic Other Mail Threshold', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', '0, 3, 0, 3, 3, 11, 11, 15, 0, 70, 0, 3, 0, 70, 0, 70, 0, 70', '<u>Maximums:</u><br>70 lb', '6', '0', 'tep_cfg_multiinput_duallist_lb(array(\'Flat Rate Envelope\', \'Sm Flat Rate Box\', \'Md Flat Rate Box\', \'Lg Flat Rate Box\', \'Standard Priority\', \'Express FltRt Env\', \'Express Standard\', \'Parcel Pst\', \'Media Mail\'), ', 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 ('Int\'l Shipping Methods', 'MODULE_SHIPPING_USPS_INTL_TYPES', 'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, USPS GXG Envelopes, Express Mail Int, Express Mail Int Flat Rate Env, Priority Mail International, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Small Box, Priority Mail Int Flat Rate Med Box, Priority Mail Int Flat Rate Lrg Box, First-Class Mail Int Lrg Env, First-Class Mail Int Package, First-Class Mail Int Letter', 'Select the international services to be offered:', '6', '0', 'tep_cfg_select_multioption(array(\'Global Express\', \'Global Express Non-Doc Rect\', \'Global Express Non-Doc Non-Rect\', \'USPS GXG Envelopes\', \'Express Mail Int\', \'Express Mail Int Flat Rate Env\', \'Priority Mail International\', \'Priority Mail Int Flat Rate Env\', \'Priority Mail Int Flat Rate Small Box\', \'Priority Mail Int Flat Rate Med Box\', \'Priority Mail Int Flat Rate Lrg Box\', \'First-Class Mail Int Lrg Env\', \'First-Class Mail Int Package\', \'First-Class Mail Int Letter\'), ', 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 ('Int\'l Rates', 'MODULE_SHIPPING_USPS_INTL_RATE', 'Retail', 'Charge retail pricing or internet pricing?', '6', '0', 'tep_cfg_select_option(array(\'Retail\', \'Internet\'), ', 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 ('Int\'l Insurance Options', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'False', 'Force USPS Calculated International Insurance?', '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 ('Int\'l Handling Fees', 'MODULE_SHIPPING_USPS_INTL_HANDLING', '0', 'Add a flat fee international shipping.', '6', '0', 'tep_cfg_multiinput_list(array(\'\'), ', 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 ('Int\'l Package Sizes', 'MODULE_SHIPPING_USPS_INTL_SIZE', '1, 1, 1, 0', 'Standard package dimensions required by USPS for international rates', '6', '0', 'tep_cfg_multiinput_list(array(\'Width\', \'Length\', \'Height\', \'Girth\'), ', 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 ('Non USPS Insurance - Domestic and international', 'MODULE_SHIPPING_USPS_INSURE', 'False', 'Would you like to charge insurance for packages independent of USPS, i.e, merchant provided, Stamps.com, Endicia? If used in conjunction with USPS calculated insurance, the higher of the two will apply.', '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, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS1', '1.75', 'Totals $.01-$50.00', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS2', '2.25', 'Totals $50.01-$100', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS3', '2.75', 'Totals $100.01-$200', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS4', '4.70', 'Totals $200.01-$300', '6', '0', 'currencies->format', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values ('Non USPS Insurance', 'MODULE_SHIPPING_USPS_INS5', '1.00', 'For every $100 over $300 (add)', '6', '0', 'currencies->format', 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', 'False', 'Would you like to insure sales tax paid by the customer?', '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 Shipping Cost?', 'MODULE_SHIPPING_USPS_INSURE_SHIPPING', 'False', 'Would you like insure the shipping cost paid by the customer?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); } function keys() { return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_PROCESSING', 'MODULE_SHIPPING_USPS_DMSTC_TYPES', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'MODULE_SHIPPING_USPS_SIG_THRESH', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', 'MODULE_SHIPPING_USPS_INTL_TYPES', 'MODULE_SHIPPING_USPS_INTL_RATE', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_INTL_HANDLING', 'MODULE_SHIPPING_USPS_INTL_SIZE', 'MODULE_SHIPPING_USPS_INSURE', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', 'MODULE_SHIPPING_USPS_INSURE_TAX', 'MODULE_SHIPPING_USPS_INSURE_SHIPPING'); } ///////////////////////////////////////// ///////// End Install Module //////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////// Remove Module ///////////// ///////////////////////////////////////// function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } ///////////////////////////////////////// ////////// End Remove Module //////////// ///////////////////////////////////////// ///////////////////////////////////////// //////////// SET DEFAULTS /////////////// ///////////////////////////////////////// function _setService($service) { $this->service = $service; } function _setWeight($pounds, $ounces=0, $weight) { $this->pounds = $pounds; $this->ounces = $ounces; $this->weight = $weight; } function _setMachinable($machinable) { $this->machinable = $machinable; } ///////////////////////////////////////// //////////// END DEFAULTS /////////////// ///////////////////////////////////////// ///////////////////////////////////////// /////////// START RATE REQUEST ////////// ///////////////////////////////////////// function _getQuote() { global $order, $transittime, $dispinsure; if (MODULE_SHIPPING_USPS_INSURE_TAX == 'True' && MODULE_SHIPPING_USPS_INSURE_SHIPPING == 'True') {$insurable = $order->info['total'];} elseif (MODULE_SHIPPING_USPS_INSURE_TAX) {$insurable = $order->info['subtotal'] + $order->info['tax'];} elseif (MODULE_SHIPPING_USPS_INSURE_SHIPPING == 'True') {$insurable = $order->info['total'] - $order->info['tax'];} else {$insurable = $order->info['subtotal'];} $transit = (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))); $dispinsurance = (in_array('Display insurance', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))); $Authentication = explode( ", ", MODULE_SHIPPING_USPS_USERID); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) ///////////////////////////////////////// ////// START USPS DOMESTIC REQUEST ////// ///////////////////////////////////////// { $request = '<RateV4Request USERID="' . $Authentication[0] . '">' . '<Revision>2</Revision>'; $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); ///////////////////////////////////////// //// REQUEST IF WITHIN ALLOWED LIST ///// ///////////////////////////////////////// $allowed_types = explode(", ", MODULE_SHIPPING_USPS_DMSTC_TYPES); while (list($key, $value) = each($this->types)) { if ( !in_array($key, $allowed_types) ) continue; ///////////////////////////////////////// // REQUEST IF WITHIN WEIGHT THRESHOLDS // ///////////////////////////////////////// $FMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD); if ($key == 'First-Class Mail regimark'){ $transid = $key; $key = 'First-Class Mail'; if($this->pounds == 0) { if($FMT[0] < $this->ounces && $this->ounces <= $FMT[1]) { $transid = 'First-Class Mail regimark Letter'; $this->FirstClassMailType = 'LETTER'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else if($FMT[2] < $this->ounces && $this->ounces <= $FMT[3]) { $transid = 'First-Class Mail regimark Large Envelope'; $this->FirstClassMailType = 'FLAT'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else if($FMT[4] < $this->ounces && $this->ounces <= $FMT[5]) { $transid = 'First-Class Mail regimark Package'; $this->FirstClassMailType = 'PARCEL'; $this->machinable = 'TRUE'; $this->size = 'REGULAR'; $this->container = 'VARIABLE'; } else { $key = 'none'; } } } $OMT = explode(", ", MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD); if ($key == 'Priority Mail regimark'){ $transid = $key; if ($OMT[8] < $this->weight && $this->weight <= $OMT[9]) { $key = 'Priority Commercial'; $this->container = ''; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Flat Rate Envelope'){ $transid = $key; if ($OMT[0] < $this->weight && $this->weight <= $OMT[1]) { $key = 'Priority Commercial'; $this->container = 'FLAT RATE ENVELOPE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Small Flat Rate Box'){ $transid = $key; if ($OMT[2] < $this->weight && $this->weight <= $OMT[3]) { $key = 'Priority Commercial'; $this->container = 'SM FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Medium Flat Rate Box'){ $transid = $key; if ($OMT[4] < $this->weight && $this->weight <= $OMT[5]) { $key = 'Priority Commercial'; $this->container = 'MD FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Priority Mail regimark Large Flat Rate Box'){ $transid = $key; if ($OMT[6] < $this->weight && $this->weight <= $OMT[7]) { $key = 'Priority Commercial'; $this->container = 'LG FLAT RATE BOX'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Express Mail regimark'){ $transid = $key; if ($OMT[12] < $this->weight && $this->weight <= $OMT[13]) { $this->container = ''; $key = 'Express Commercial'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Express Mail regimark Flat Rate Envelope'){ $transid = $key; if ($OMT[10] < $this->weight && $this->weight <= $OMT[11]) { $key = 'Express Commercial'; $this->container = 'FLAT RATE ENVELOPE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Parcel Post regimark'){ $transid = $key; $key = 'Parcel Post'; if ($OMT[14] < $this->weight && $this->weight <= $OMT[15]){ $this->machinable = 'TRUE'; $this->size = 'REGULAR'; } else { $key = 'none'; } } if ($key == 'Media Mail regimark'){ $transid = $key; $key = 'Media Mail'; if ($OMT[16] < $this->weight && $this->weight <= $OMT[17]){ $this->size = 'REGULAR'; } else { $key = 'none'; } } ///////////////////////////////////////////// // END REQUEST IF WITHIN WEIGHT THRESHOLDS // ///////////////////////////////////////////// $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<FirstClassMailType>' . $this->FirstClassMailType . '</FirstClassMailType>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Value>' . $insurable . '</Value>' . '<Machinable>' . $this->machinable . '</Machinable>' . '<ShipDate>' . date('d-M-Y') . '</ShipDate>' . '</Package>'; ///////////////////////////////////////// ////// START USPS TRANSIT REQUEST /////// ///////////////////////////////////////// if($transit) { $transitreq = 'USERID="' . $Authentication[0] . '">' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>'; switch ($key) { case 'First-Class Mail': $transreq[$transid] = 'API=PriorityMail&XML=' . urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; case 'Media Mail': $transreq[$transid] = 'API=StandardB&XML=' . urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; case 'Parcel Post': $transreq[$transid] = 'API=StandardB&XML=' . urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); break; case 'Priority Commercial': $transreq[$transid] = 'API=PriorityMail&XML=' . urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); break; default: $transreq[$transid] = ''; break; } } ///////////////////////////////////////// //////// END USPS TRANSIT REQUEST /////// ///////////////////////////////////////// $services_count++; } ///////////////////////////////////////// ////// END IF WITHIN ALLOWED LIST /////// ///////////////////////////////////////// $request .= '</RateV4Request>'; $request = 'API=RateV4&XML=' . urlencode($request); } ///////////////////////////////////////// /////// END USPS DOMESTIC REQUEST /////// ///////////////////////////////////////// else ///////////////////////////////////////// //// START USPS INTERNATIONAL REQUEST /// ///////////////////////////////////////// { $request = '<IntlRateV2Request USERID="' . $Authentication[0] . '">' . '<Revision>2</Revision>' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Machinable>True</Machinable>' . '<MailType>Package</MailType>' . '<GXG>' . '<POBoxFlag>N</POBoxFlag>' . '<GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>' . $insurable . '</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '<Container>RECTANGULAR</Container>' . '<Size>REGULAR</Size>' ; $IPS = explode(", ", MODULE_SHIPPING_USPS_INTL_SIZE); $request .= '<Width>' . $IPS[0] . '</Width>' . '<Length>' . $IPS[1] . '</Length>' . '<Height>' . $IPS[2] . '</Height>' . '<Girth>' . $IPS[3] . '</Girth>' . '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' . '<CommercialFlag>Y</CommercialFlag>' . '<ExtraServices>' . '<ExtraService>1</ExtraService>' . '<ExtraService>2</ExtraService>' . '</ExtraServices>' . '</Package>' . '</IntlRateV2Request>'; $request = 'API=IntlRateV2&XML=' . urlencode($request); } ///////////////////////////////////////// //// END USPS INTERNATIONAL REQUEST ///// ///////////////////////////////////////// ///////////////////////////////////////// /////// USPS HTTP COMMUNICATION ///////// ///////////////////////////////////////// $usps_server = 'production.shippingapis.com'; $api_dll = 'shippingAPI.dll'; $body = ''; if (!class_exists('httpClient')) { include('includes/classes/http_client.php'); } $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(); // mail('[email protected]','USPS Transit Response',$transresp[$key],'From: <[email protected]>'); } } $http->Disconnect(); } else { return false; } $body = htmlspecialchars_decode($body); $body = preg_replace('/\<sup\>\®\<\/sup\>/', ' regimark', $body); $body = preg_replace('/\<sup\>\™\<\/sup\>/', ' tradmrk', $body); ///////////////////////////////////////// /////END USPS HTTP COMMUNICATION //////// ///////////////////////////////////////// ///////////////////////////////////////// /////////// START RATE RESPONSE ///////// ///////////////////////////////////////// $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(); $rates_sorter = array(); if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) { ///////////////////////////////////////// ///////// START DOMESTIC RESPONSE /////// ///////////////////////////////////////// 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], '<Rate>')) { $service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs); $service = $regs[1]; if ((MODULE_SHIPPING_USPS_DMSTC_RATE == 'Internet') && preg_match('/CommercialRate/', $response[$i])) { $postage = ereg('<CommercialRate>(.*)</CommercialRate>', $response[$i], $regs); $postage = $regs[1];} else { $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs); $postage = $regs[1];} if (preg_match('/Insurance<\/ServiceName><Available>true<\/Available><AvailableOnline>true/', $response[$i])) { $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs); $insurance = $regs[1];} elseif (preg_match('/Insurance<\/ServiceName><Available>true<\/Available><AvailableOnline>false/', $response[$i])) { $insurance = ereg('Insurance</ServiceName><Available>true</Available><AvailableOnline>false</AvailableOnline><Price>(.*)</Price>', $response[$i], $regs); $insurance = $regs[1];} else { $insurance = 0; } if ($insurable<=50) {$uinsurance=MODULE_SHIPPING_USPS_INS1;} else if ($insurable<=100) {$uinsurance=MODULE_SHIPPING_USPS_INS2;} else if ($insurable<=200) {$uinsurance=MODULE_SHIPPING_USPS_INS3;} else if ($insurable<=300) {$uinsurance=MODULE_SHIPPING_USPS_INS4;} else {$uinsurance = MODULE_SHIPPING_USPS_INS4 + ((ceil($insurable/100) -3) * MODULE_SHIPPING_USPS_INS5);} if (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True') {$postage = $postage + max($insurance, $uinsurance);} elseif (MODULE_SHIPPING_USPS_INSURE == 'True') {$postage = $postage + $uinsurance;} elseif (MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0) {$postage = $postage + $insurance;} if ((MODULE_SHIPPING_USPS_DMST_DEL_CONF == 'True') && (preg_match('/<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>0.80<\/Price><PriceOnline>/', $response[$i]))) { $del_conf = ereg('</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>0.80</Price><PriceOnline>(.*)</PriceOnline>', $response[$i], $regs); $del_conf = $regs[1]; $postage = $postage + $del_conf; } if ((MODULE_SHIPPING_USPS_DMST_SIG_CONF == 'True') && ($this->sig_conf_thresh <= $order->info['subtotal'])&& (preg_match('/<\/ServiceName><Available>true<\/Available><AvailableOnline>true<\/AvailableOnline><Price>2.35<\/Price><PriceOnline>/', $response[$i]))) { $sig_conf = ereg('</ServiceName><Available>true</Available><AvailableOnline>true</AvailableOnline><Price>2.35</Price><PriceOnline>(.*)</PriceOnline>', $response[$i], $regs); $sig_conf = $regs[1]; $postage = $postage + $sig_conf; } switch ($service) { case 'First-Class Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Letter': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Large Envelope': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[0]; break; case 'First-Class Mail regimark Package': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[0]; break; case 'Media Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[1]; break; case 'Parcel Post regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[2]; break; case 'Priority Mail regimark': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[3]; break; case 'Priority Mail regimark Flat Rate Envelope': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[4]; break; case 'Priority Mail regimark Small Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[5]; break; case 'Priority Mail regimark Medium Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[6]; break; case 'Priority Mail regimark Large Flat Rate Box': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($time + $this->processing);} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') { $time .= MODULE_SHIPPING_USPS_TEXT_DAY; } else { $time .= MODULE_SHIPPING_USPS_TEXT_DAYS; } $postage = $postage + $this->dmstc_handling[7]; break; case 'Express Mail regimark': $time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs); $time = $regs[1]; if ($time == 'Overnight to many areas' && $this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS;;} elseif ($time == 'Overnight to many areas') {$time = '---' . $time;} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') {$time .= MODULE_SHIPPING_USPS_TEXT_DAY;} elseif ($time > '2' && $time <= '9') {$time .= MODULE_SHIPPING_USPS_TEXT_DAYS;} $postage = $postage + $this->dmstc_handling[8]; break; case 'Express Mail regimark Flat Rate Envelope': $time = ereg('<CommitmentDate>(.*)</CommitmentDate>', $response[$i], $regs); $time = $regs[1]; if ($time == 'Overnight to many areas' && $this->processing > 0) {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . ($this->processing + 1) . MODULE_SHIPPING_USPS_TEXT_DAYS;;} elseif ($time == 'Overnight to many areas') {$time = '---' . $time;} else {$time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $time;} if ($time == '1') {$time .= MODULE_SHIPPING_USPS_TEXT_DAY;} elseif ($time > '2' && $time <= '9') {$time .= MODULE_SHIPPING_USPS_TEXT_DAYS;} $postage = $postage + $this->dmstc_handling[8]; break; } if (($dispinsurance) && ((MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION == 'True' && $insurance > 0) || (MODULE_SHIPPING_USPS_INSURE == 'True' && $uinsurance > 0))) {$dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2);} else {$dispinsure[$service] = '';} if (($transit) && ($time != '')) {$transittime[$service] = '<br>' . $time;} else {$transittime[$service] = '';} $rates[] = array($service => $postage); $rates_sorter[] = $postage; } } } ///////////////////////////////////////// ////////// END DOMESTIC RESPONSE //////// ///////////////////////////////////////// else ///////////////////////////////////////// ////// START INTERNATIONAL RESPONSE ///// ///////////////////////////////////////// { 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(", ", MODULE_SHIPPING_USPS_INTL_TYPES) 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]; $CMP = ereg('<CommercialPostage>(.*)</CommercialPostage>', $services[$i], $regs); $CMP = $regs[1]; if ($CMP == 0) { $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; } else{ switch (MODULE_SHIPPING_USPS_INTL_RATE) { case 'Internet': if (preg_match('/<CommercialPostage>/', $services[$i])) { $postage = ereg('<CommercialPostage>(.*)</CommercialPostage>', $services[$i], $regs); $postage = $regs[1]; } else { $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; } break; case 'Retail': $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; break; } } $postage = $postage + $this->intl_handling[0]; if (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i])) { $iinsurance = ereg('Insurance</ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); $iinsurance = $regs[1];} else {$iinsurance = 0;} if ($insurable<=50) {$iuinsurance=MODULE_SHIPPING_USPS_INS1;} else if ($insurable<=100) {$iuinsurance=MODULE_SHIPPING_USPS_INS2;} else if ($insurable<=200) {$iuinsurance=MODULE_SHIPPING_USPS_INS3;} else if ($insurable<=300) {$iuinsurance=MODULE_SHIPPING_USPS_INS4;} else {$iuinsurance = MODULE_SHIPPING_USPS_INS4 + ((ceil($insurable/100) -3) * MODULE_SHIPPING_USPS_INS5);} if (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && MODULE_SHIPPING_USPS_INSURE == 'True') {$postage = $postage + max($iinsurance, $iuinsurance);} elseif (MODULE_SHIPPING_USPS_INSURE == 'True') {$postage = $postage + $iuinsurance;} elseif (MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True') {$postage = $postage + $iinsurance;} $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs); $time = MODULE_SHIPPING_USPS_TEXT_ESTIMATED . $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; } if (($dispinsurance) && ((MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION == 'True' && $iinsurance > 0) || (MODULE_SHIPPING_USPS_INSURE == 'True' && $iuinsurance > 0))) {$dispinsure[$service] = '<br>' . MODULE_SHIPPING_USPS_TEXT_INSURED . '$' . tep_round_up($insurable, 2);} else {$dispinsure[$service] = '';} if (($transit) && ($time != '')) {$transittime[$service] = '<br>' . $time;} else {$transittime[$service] = '';} $rates[] = array($service => $postage); $rates_sorter[] = $postage; } } } } asort($rates_sorter); $sorted_rates = array(); foreach (array_keys($rates_sorter) as $key){ $sorted_rates[] = $rates[$key]; } ///////////////////////////////////////// /////// END INTERNATIONAL RESPONSE ////// ///////////////////////////////////////// return ((sizeof($sorted_rates) > 0) ? $sorted_rates : false); } ///////////////////////////////////////// /////////// END RATE RESPONSE//////////// ///////////////////////////////////////// } ///////////////////////////////////////// ////////// Ends USPS Class /////////// ///////////////////////////////////////// ?> Quote Link to comment Share on other sites More sharing options...
Guest Posted March 24, 2011 Share Posted March 24, 2011 lol, no need to post the code. I know the code. USPS doesn't require a password anymore. I don't have the energy or desire to turn off JUST one shipping method for international, but I can give you code for something else because I customized my own code to add it. Instead of cutting off first class after a value of $20, you could require registered mail, which runs $10.58 I think, and brings first class mail to the same price range as priority international, but WITH registration. Also consider that flat rate envelopes do NOT get tracked. Only regular priority has any sort of tracking and only registered mail gives you any way of filing a claim. This code will only add registered mail rates for first class as far as I know. Here it is: find around line 42: $this->sig_conf_thresh = MODULE_SHIPPING_USPS_SIG_THRESH; add after: $this->sig_reg_thresh = MODULE_SHIPPING_USPS_SIG_THRESH; Somewhere around line 425 in the blob of db entries, add these two lines: 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 ('Int\'l Registered Mail', 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'True', 'Force Registered Mail for untracked International packages? Registered mail cannot be purchased online and must be paid for at a USPS counter.', '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, date_added) values ('Registered Mail Threshold', 'MODULE_SHIPPING_USPS_REG_THRESH', '20', 'Order total required before Registered Mail is triggered?', '6', '0', now())"); find the key function around line 440 - it'll look something like this: function keys() { return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_PROCESSING', 'MODULE_SHIPPING_USPS_DMSTC_TYPES', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'MODULE_SHIPPING_USPS_SIG_THRESH', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING_PERC', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', 'MODULE_SHIPPING_USPS_INTL_TYPES', 'MODULE_SHIPPING_USPS_INTL_RATE', 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'MODULE_SHIPPING_USPS_REG_THRESH', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_INTL_HANDLING', 'MODULE_SHIPPING_USPS_INTL_HANDLING_PERC', 'MODULE_SHIPPING_USPS_INTL_SIZE', 'MODULE_SHIPPING_USPS_INSURE', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', 'MODULE_SHIPPING_USPS_INSURE_TAX'); } within that line, find: 'MODULE_SHIPPING_USPS_INTL_RATE' add right after (in the same line): , 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'MODULE_SHIPPING_USPS_REG_THRESH' find around line 1100: $postage = $postage + $this->intl_handling[0]; add after: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); $registered = $regs[1]; $postage = $postage + $registered;} Uninstall and reinstall the module from admin panel. Anything with a value over $20 will require registered mail and you can change that threshold to suit your needs. Please note that there is actually a support forum for this module. The link is in the instructions near the top. Also, the line numbers I gave are going to be off because my personal code is different from the contribution. Jetta Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted March 25, 2011 Author Share Posted March 25, 2011 That sounds awesome. I have implemented it and its installed and working. I need to test it properly but so far looking good. Thanks so much for your help. Johnathan Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted March 25, 2011 Author Share Posted March 25, 2011 lol, no need to post the code. I know the code. USPS doesn't require a password anymore. I don't have the energy or desire to turn off JUST one shipping method for international, but I can give you code for something else because I customized my own code to add it. Instead of cutting off first class after a value of $20, you could require registered mail, which runs $10.58 I think, and brings first class mail to the same price range as priority international, but WITH registration. Also consider that flat rate envelopes do NOT get tracked. Only regular priority has any sort of tracking and only registered mail gives you any way of filing a claim. This code will only add registered mail rates for first class as far as I know. Here it is: find around line 42: $this->sig_conf_thresh = MODULE_SHIPPING_USPS_SIG_THRESH; add after: $this->sig_reg_thresh = MODULE_SHIPPING_USPS_SIG_THRESH; Somewhere around line 425 in the blob of db entries, add these two lines: 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 ('Int\'l Registered Mail', 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'True', 'Force Registered Mail for untracked International packages? Registered mail cannot be purchased online and must be paid for at a USPS counter.', '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, date_added) values ('Registered Mail Threshold', 'MODULE_SHIPPING_USPS_REG_THRESH', '20', 'Order total required before Registered Mail is triggered?', '6', '0', now())"); find the key function around line 440 - it'll look something like this: function keys() { return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_PROCESSING', 'MODULE_SHIPPING_USPS_DMSTC_TYPES', 'MODULE_SHIPPING_USPS_DMSTC_RATE', 'MODULE_SHIPPING_USPS_DMST_DEL_CONF', 'MODULE_SHIPPING_USPS_DMST_SIG_CONF', 'MODULE_SHIPPING_USPS_SIG_THRESH', 'MODULE_SHIPPING_USPS_DMSTC_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING', 'MODULE_SHIPPING_USPS_DMSTC_HANDLING_PERC', 'MODULE_SHIPPING_USPS_DMSTC_FIRSTCLASS_THRESHOLD', 'MODULE_SHIPPING_USPS_DMSTC_OTHER_THRESHOLD', 'MODULE_SHIPPING_USPS_INTL_TYPES', 'MODULE_SHIPPING_USPS_INTL_RATE', 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'MODULE_SHIPPING_USPS_REG_THRESH', 'MODULE_SHIPPING_USPS_INTL_INSURANCE_OPTION', 'MODULE_SHIPPING_USPS_INTL_HANDLING', 'MODULE_SHIPPING_USPS_INTL_HANDLING_PERC', 'MODULE_SHIPPING_USPS_INTL_SIZE', 'MODULE_SHIPPING_USPS_INSURE', 'MODULE_SHIPPING_USPS_INS1', 'MODULE_SHIPPING_USPS_INS2', 'MODULE_SHIPPING_USPS_INS3','MODULE_SHIPPING_USPS_INS4', 'MODULE_SHIPPING_USPS_INS5', 'MODULE_SHIPPING_USPS_INSURE_TAX'); } within that line, find: 'MODULE_SHIPPING_USPS_INTL_RATE' add right after (in the same line): , 'MODULE_SHIPPING_USPS_INTL_REGISTERED', 'MODULE_SHIPPING_USPS_REG_THRESH' find around line 1100: $postage = $postage + $this->intl_handling[0]; add after: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); $registered = $regs[1]; $postage = $postage + $registered;} Uninstall and reinstall the module from admin panel. Anything with a value over $20 will require registered mail and you can change that threshold to suit your needs. Please note that there is actually a support forum for this module. The link is in the instructions near the top. Also, the line numbers I gave are going to be off because my personal code is different from the contribution. Jetta Got around to testing it today and its not adding the cost for reg on international. I went in checked and i put all the code you said in the correct places. Its showing up fine in the admin and i set that to "true" and "20" value. Trying checkout with a 64.99 item to Canada and UK both not adding reg. Everything else seems to be working good. any ideas? Do you want me to show my usps.php Thanks. Quote Link to comment Share on other sites More sharing options...
Guest Posted March 28, 2011 Share Posted March 28, 2011 Oops, I gave you bad code: Instead of this: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); Try this: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Registered Mail<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); It was searching for insurance, not registered mail. Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted March 30, 2011 Author Share Posted March 30, 2011 Oops, I gave you bad code: Instead of this: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Insurance<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); Try this: if ((MODULE_SHIPPING_USPS_INTL_REGISTERED == 'True') && ($this->sig_reg_thresh <= $order->info['subtotal']) && (preg_match('/Registered Mail<\/ServiceName><Available>True/', $services[$i]))) { $registered = ereg('Registered Mail<\/ServiceName><Available>True</Available><Price>(.*)</Price>', $services[$i], $regs); It was searching for insurance, not registered mail. I appreciate you taking the time to message back. I'll give this a try and let you know. regards Johnathan Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted March 30, 2011 Author Share Posted March 30, 2011 I appreciate you taking the time to message back. I'll give this a try and let you know. regards Johnathan I updated the USPS.php but before that i had (thought i had) fix the regimark problem as it was showing up regimark. I uploaded the newer USPS moduel files like general.php and so on and it fixed the regimark and it shows up as the proper reg logo. Now however when i tried to remove and install the usps model in admin it shows up many of the options as Array after i click save. For example i edit the usps model and type in the USPS ID then click save and it will change it to array after been saved. Do you have any idea what the crap I've managed to do lol Quote Link to comment Share on other sites More sharing options...
Guest Posted March 31, 2011 Share Posted March 31, 2011 There is a reason for it but I can't remember what the crap causes that - haha. You had to uninstall the old module before installing the new module in order to clear the old configuration out of the db. If you didn't, then you need to uninstall the module and either go through mysql and do a search for usps in the configuration table and delete all entries or reinstall the old module, uninstall it, then reinstall the new module. Are you confused yet? But, I think the problem is actually in one of the other files, more than likely the admin/functions/general.php. There was a modification to be made to that file. Check to make sure it's been done. Quote Link to comment Share on other sites More sharing options...
Dr_killer_UK Posted April 3, 2011 Author Share Posted April 3, 2011 There is a reason for it but I can't remember what the crap causes that - haha. You had to uninstall the old module before installing the new module in order to clear the old configuration out of the db. If you didn't, then you need to uninstall the module and either go through mysql and do a search for usps in the configuration table and delete all entries or reinstall the old module, uninstall it, then reinstall the new module. Are you confused yet? But, I think the problem is actually in one of the other files, more than likely the admin/functions/general.php. There was a modification to be made to that file. Check to make sure it's been done. Managed to fix that by using my backed up original admin/modules.php and modifying it for the USPS module again. Unfortunately the reg is still not been added at checkout. Any other ideas. Made sure the USPS.php had the last correction in correctly that you mentioned. thanks Johnathan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.