Jump to content
Sign in to follow this  
Kazsil

USPS rates with dimensions?

Recommended Posts

I have looked everywhere and haven't been able to find and addon for USPS that would allow for the rate to be based on dimensions of the package it only goes by weight. And the rates are way off from accurate.

 

I see the addon "UPS XML Rates" and it looks great but my client would like to use USPS since it is generally a cheaper way to ship.

 

My client has almost all his inventory already boxed in the original packaging, so it is a "ready to ship" type situation.

Is there an addon that I am just not finding? Or is there a way to do this that I am just not thinking of (like installing the UPS XML addon and augmenting the USPS.php file so it calls the h w d from the dBASE?)

 

I have osC v 2.2 rc2

 

I would really really be grateful as this is something I have to figure out!

 

Thanks so much advance! :D

Jen

Share this post


Link to post
Share on other sites

Or is there a way to do this that I am just not thinking of (like installing the UPS XML addon and augmenting the USPS.php file so it calls the h w d from the dBASE?)

All the general instructions for dimensional support of UPSXML can be followed (like changing admin/categories.php to add dimensions) because they will be the same for every shipping module. Then the object $packing which is instantiated in checkout_shipping.php can be used to pack the products and get information about the boxes with dimensions and weight. That information has to find its way into the xml that is sent to USPS.

 

Personally, I never looked at that. One reason being not having access to the USPS service. The same with FedEx that (to me at least) appears to hide the relevant information to implement this from visitors to their website. Not that UPS is any better in that respect :)

Share this post


Link to post
Share on other sites

All the general instructions for dimensional support of UPSXML can be followed (like changing admin/categories.php to add dimensions) because they will be the same for every shipping module. Then the object $packing which is instantiated in checkout_shipping.php can be used to pack the products and get information about the boxes with dimensions and weight. That information has to find its way into the xml that is sent to USPS.

 

Personally, I never looked at that. One reason being not having access to the USPS service. The same with FedEx that (to me at least) appears to hide the relevant information to implement this from visitors to their website. Not that UPS is any better in that respect :)

 

Thanks Jan!

I will give it a try and let you know how it comes out.

Jen

Share this post


Link to post
Share on other sites

All the general instructions for dimensional support of UPSXML can be followed (like changing admin/categories.php to add dimensions) ....

 

 

Jan,

I am having an issue with the USPSxml quotes. I am just trying to get UPS to give me accurate quotes.

It is the oddest thing. But for every package i have it puts #packages X 9 as the weight on all quotes except ground. See here:

 

Actual quote for weight=10 lbs in 3 packages....

United Parcel Service (3 pkgs, 10 lbs total) United Parcel Service

UPS Ground (billed dimensional weight 10 LBS) $30.62

UPS 3 Day Select (billed dimensional weight 27 LBS) $48.27

UPS 2nd Day Air (billed dimensional weight 27 LBS) $62.22

UPS Next Day Air Saver (billed dimensional weight 27 LBS) $98.97

UPS Next Day Air (billed dimensional weight 27 LBS) $112.44

UPS Next Day Air Early A.M. (billed dimensional weight 27 LBS) $212.88

Ground is correct weight, but all the others are a 9x3=27 lbs.

 

Another is:

United Parcel Service (4 pkgs, 16 lbs total) United Parcel Service

UPS Ground (billed dimensional weight 16 LBS) $41.50

UPS 3 Day Select (billed dimensional weight 36 LBS) $64.36

UPS 2nd Day Air (billed dimensional weight 36 LBS) $82.96

UPS Next Day Air Saver (billed dimensional weight 36 LBS) $131.96

UPS Next Day Air (billed dimensional weight 36 LBS) $149.92

UPS Next Day Air Early A.M. (billed dimensional weight 36 LBS) $283.84

Ground is correct weight again, but all others are 9x4=36....

 

On all services except Ground it is disregarding the true weight and using (#pkgs X 9) for the weight. So it has to be multiplying the amount of packages x 9 for some reason. Except for UPS Ground... that one is perfect!

 

I have cleared my tar to 0, no handling fee.

 

What am I missing??

I have re-looked at my code and from what I see, i did the installs correctly.

 

I did check the Tools->Packaging and I have set them to empty weight=0 max weight=0 cost=1

 

Is there a setting somewhere I am not setting that would have a default box weight to 9lbs on all UPS services except Ground?

 

I would truly appreciate your feedback and help because I have been struggling with this for a week!

(I haven't even gotten to the USPS yet! Sigh.)

 

Thanks in advance :blush:

Jen

Share this post


Link to post
Share on other sites

United Parcel Service (3 pkgs, 10 lbs total) United Parcel Service

UPS Ground (billed dimensional weight 10 LBS) $30.62

UPS 3 Day Select (billed dimensional weight 27 LBS) $48.27

UPS 2nd Day Air (billed dimensional weight 27 LBS) $62.22

UPS Next Day Air Saver (billed dimensional weight 27 LBS) $98.97

UPS Next Day Air (billed dimensional weight 27 LBS) $112.44

UPS Next Day Air Early A.M. (billed dimensional weight 27 LBS) $212.88

Ground is correct weight, but all the others are a 9x3=27 lbs.

 

In case anyone stumbles upon this issue with the UPS dimensional weight being wrong, I posted the solution here

 

I will be attempting the USPS dimensional shipping now and will post my progress in case anyone needs it in the future.

Jen

Share this post


Link to post
Share on other sites

I have got it almost working... I can call USPS using the dimensional support and it returns the values of all the boxes correctly.

Problem I am having is right now it list a rate for each box instead of combining the prices.

So The user right now will see this:

 

United States Postal Service (3 pkgs with 21 lbs total) United States Postal Service

Express Mail $31.00

Priority Mail $10.90

Parcel Post $9.18

Express Mail $31.00

Priority Mail $10.90

Parcel Post $9.18

Express Mail $15.70

Priority Mail $4.90

Parcel Post $4.90

 

So I have it working that it does indeed quote each package prices, but I need to be able to show one price per service type.

Any Idea how to do that??

I think there needs to be a loop somewhere that combines the arrays.

This is where I think it might need to go in the code.

 $uspsQuote = $this->_getQuote();
//echo '<pre>Packages and variables:<br />';
       // print_r($uspsQuote);
       //echo '<br />';
     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 . ' (' . count($boxesToShip) . ' pkgs with ' . $shipping_weight . ' lbs total)');

         $methods = array();
         $size = sizeof($uspsQuote);
         for ($i=0; $i<$size; $i++) {
           list($type, $cost) = each($uspsQuote[$i]);

//echo "USPS $type @ $cost<br>"; 
    if (($method == '' && in_array($type, $this->types)) || $method == $type) {
       if (strpos($type, "Flat Rate")) $type_flat = $type . ', subject to verification';
       else $type_flat = $type;
              $methods[] = array('id' => $type,
                              'title' => $type_flat,
                              'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) );
           }
         }

         $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;

 

I just cant figure out what to do to combine them into one price per service.

Any help would be greatly appreciate!!

Jen

Share this post


Link to post
Share on other sites

Ok! I have made it so the USPS works with "UPSxml with Dimensional Support"!

You will need to install this first: http://www.oscommerce.com/community/contributions,1323

 

Install the dimensional Support also which is included in the add-on.

 

Then you will need to change your includes/modules/shipping/USPS.php file to this:

 

<?php
/*
 $Id: usps.php 1783 2008-01-10 01:16:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2008 osCommerce

 Released under the GNU General Public License
*/

// Incorporate the XML conversion library 
 if (PHP_VERSION >= '5.0.0') { // PHP 5 does not need to use call-time pass by reference
   require_once (DIR_WS_CLASSES . 'xml_5.php');
 } else {
   require_once (DIR_WS_CLASSES . 'xml.php');
 }

 class usps {
   var $code, $title, $description, $icon, $enabled, $countries, $types, $boxcount;

// class constructor
   function usps() {
     global $order,  $packing;

     $this->code = 'usps';
  $this->items_qty = 0;
     $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);
// the variables for unit weight, unit length, and dimensions support were moved to
// shop admin -> Configuration -> Shipping/Packaging in
// version 1.3.0. Run the configuration_shipping.sql to add these to your configuration
       if (defined('SHIPPING_UNIT_WEIGHT')) {
         $this->unit_weight = SHIPPING_UNIT_WEIGHT;
       } else {
// for those who will undoubtedly forget or not know how to run the configuration_shipping.sql
// we will set the default to pounds (LBS) and inches (IN)
         $this->unit_weight = 'LBS';
       }

       if (defined('SHIPPING_UNIT_LENGTH')) {
         $this->unit_length = SHIPPING_UNIT_LENGTH;
       } else {
         $this->unit_length = 'IN';
       }
       if (defined('SHIPPING_DIMENSIONS_SUPPORT') && SHIPPING_DIMENSIONS_SUPPORT == 'Ready-to-ship only') {
         $this->dimensions_support = 1;
       } elseif (defined('SHIPPING_DIMENSIONS_SUPPORT') && SHIPPING_DIMENSIONS_SUPPORT == 'With product dimensions') {
         $this->dimensions_support = 2;
       } else {
         $this->dimensions_support = 0;
       }
     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
       $check_flag = false;
       $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
       while ($check = tep_db_fetch_array($check_query)) {
         if ($check['zone_id'] < 1) {
           $check_flag = true;
           break;
         } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = false;
       }
     }

$this->types = explode( ", ", MODULE_SHIPPING_USPS_TYPES);
/*
     $this->types = array(
		// Domestic 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',
			'First-Class Mail Flat',
			'First-Class Mail Parcel',
			'Parcel Post',
			'Bound Printed Matter',
			'Media Mail',
			'Library Mail',
		// International Types
			'Global Express Guaranteed (GXG)',
               'Global Express Guaranteed Non-Document Rectangular',
               'Global Express Guaranteed Non-Document Non-Rectangular',
	        'USPS GXG Envelopes',
               'Express Mail International',
               'Express Mail International Flat Rate Envelope',
               'Priority Mail International',
               'Priority Mail International Large Flat Rate Box',
               'Priority Mail International Medium Flat Rate Box',
               'Priority Mail International Small Flat Rate Box',
               'Priority Mail International Flat Rate Envelope',
               'First-Class Mail International Package',
               'First-Class Mail International Large Envelope'
		);
*/
     $this->countries = $this->country_list();
   }//end function

// class methods
   function quote($method = '') {
     global $order, $shipping_weight, $shipping_num_boxes, $total_weight, $boxcount, $cart, $packing;

//	$methodsSelected = explode( ", ", MODULE_SHIPPING_USPS_TYPES);
// the check on $packing being an object will puzzle people who do things wrong (no changes when 
// you enable dimensional support without changing checkout_shipping.php) but better be safe
       if ($this->dimensions_support > 0 && is_object($packing)) {
         $boxValue = 0;
         $totalWeight = $packing->getTotalWeight();
         $boxesToShip = $packing->getPackedBoxes();
         for ($i = 0; $i < count($boxesToShip); $i++) {
           $this->_addItem($boxesToShip[$i]['item_length'], $boxesToShip[$i]['item_width'], $boxesToShip[$i]['item_height'], $boxesToShip[$i]['item_weight'], $boxesToShip[$i]['item_price']);
         } // end for ($i = 0; $i < count($boxesToShip); $i++)
       } else {
           // The old method. Let osCommerce tell us how many boxes, plus the weight of each (or total? - might be sw/num boxes)
         $this->items_qty = 0; //reset quantities
// $this->pkgvalue has been set as order subtotal around line 108, it will cause overcharging
// of insurance if not divided by the number of boxes
         for ($i = 0; $i < $shipping_num_boxes; $i++) {
           $this->_addItem(0, 0, 0, $shipping_weight, number_format(($this->pkgvalue/$shipping_num_boxes), 2, '.', ''));
         }
       }
     if ( tep_not_null($method) && in_array($method, $this->types)) {
//      if ( tep_not_null($method) && in_array($method, $methodsSelected)) {
        $this->_setService($method);
     }

     $this->_setMachinable('False');
     $this->_setContainer('None');
     $this->_setSize('REGULAR');

// usps doesnt accept zero weight
 /*    $shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);
     $shipping_pounds = floor ($shipping_weight);
     $shipping_ounces = round(16 * ($shipping_weight - floor($shipping_weight)));
     $this->_setWeight($shipping_pounds, $shipping_ounces);
  */

     $uspsQuote = $this->_getQuote();
  //usort($uspsQuote, array($this, "rate_sort_func"));
echo '<pre>Packages and variables:<br />';
        print_r($uspsQuote);
        echo '<br />';
     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 . ' (' . count($boxesToShip) . ' pkgs with ' . $shipping_weight . ' lbs total)');

         $methods = array();
	  $typeArray= array();
         $size = sizeof($uspsQuote);
         for ($i=0; $i<$size; $i++) {
           list($type, $cost) = each($uspsQuote[$i]);
		if (array_key_exists($type, $typeArray)){
			extract($typeArray);
			$cost2= $typeArray[$type] + $cost;
			$typeArray[$type] = $cost2; 				
		}else{
			//$costTotal = $cost;
			$typeArray[$type]=$cost;
		}// end if
	  }//end for loop
	  asort($typeArray);  // Sorts the quotes in asc order
         foreach ($typeArray as $key => $value) {
	  if (($method == '' && in_array($key, $this->types)) || $method == $key) {
	  $methods[] = array('id' => $key,
                              'title' => $key,
                              'cost' => ($value + MODULE_SHIPPING_USPS_HANDLING) );
						   }//end if
	  }//end foreach

         $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);
						  //print $this->quotes['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', 'False', '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, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Password', 'MODULE_SHIPPING_USPS_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'Handling fee for this shipping method.', '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, 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 ('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, First-Class Mail Flat, First-Class Mail Parcel, Parcel Post, Bound Printed Matter, Media Mail, Library Mail, Global Express Guaranteed (GXG), Global Express Guaranteed Non-Document Rectangular, Global Express Guaranteed Non-Document Non-Rectangular, USPS GXG Envelopes,Express Mail International, Express Mail International Flat Rate Envelope, Priority Mail International, Priority Mail International Large Flat Rate Box, Priority Mail International Medium Flat Rate Box,Priority Mail International Small Flat Rate Box, Priority Mail International Flat Rate Envelope, First-Class Mail International Package, First-Class Mail International Large Envelope', 'Select the 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\',\'First-Class Mail Flat\', \'First-Class Mail Parcel\', \'Parcel Post\', \'Bound Printed Matter\', \'Media Mail\', \'Library Mail\', \'Global Express Guaranteed (GXG)\', \'Global Express Guaranteed Non-Document Rectangular\',\'Global Express Guaranteed Non-Document Non-Rectangular\', \'USPS GXG Envelopes\', \'Express Mail International\', \'Express Mail International Flat Rate Envelope\', \'Priority Mail International\', \'Priority Mail International Large Flat Rate Box\',\'Priority Mail International Medium Flat Rate Box\', \'Priority Mail International Small Flat Rate Box\', \'Priority Mail International Flat Rate Envelope\', \'First-Class Mail International Package\', \'First-Class Mail International Large Envelope\'), ', 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_PASSWORD', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TYPES');
   }

   function _setService($service) {
     $this->service = $service;
   }

   function _setWeight($pounds, $ounces=0) {
     $this->pounds = $pounds;
     $this->ounces = $ounces;
   }

   function _setContainer($container) {
     $this->container = $container;
   }

   function _setSize($size) {
     $this->size = $size;
   }

   function _setMachinable($machinable) {
     $this->machinable = $machinable;
   }

    function _addItem($length, $width, $height, $weight, $price = 0 ) {
       // Add box or item to shipment list. Round weights to 1 decimal places.
       if ((float)$weight < 1.0) {
           $weight = 1;
       } else {
           $weight = round($weight, 1);
       }
       $index = $this->items_qty;
       $this->item_length[$index] = ($length ? (string)$length : '0' );
       $this->item_width[$index] = ($width ? (string)$width : '0' );
       $this->item_height[$index] = ($height ? (string)$height : '0' );
       $this->item_weight[$index] = ($weight ? (string)$weight : '0' );
       $this->item_price[$index] = $price;
       $this->items_qty++;
	//print '<BR><BR> '. $this->item_weight[$index] . ' prince' . $this->item_price[$index] .' index = '. $index .'<BR><BR>';
   }

   function _getQuote() {
     global $order;

     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
  $request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' ;
       $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
       if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);
	$numgroups = ceil($this->items_qty / 50); // UPS can only process 50 packages at once
       $xmlResult = '';
       for ($g = 0; $g < $numgroups; $g++) { // process each group of packages
       $ratingServiceSelectionRequestPackageContent = '';
       $start = 0;
       $end = ($g + 1 == $numgroups) ? $this->items_qty : $start + 50; // if last group end with number of packages otherwise do 50 more
       for ($i = $start; $i < $end; $i++) {

    $request .='<Package ID="'.$i.'">' .
      '<Service>'. 'ALL' .'</Service>' .
             '<ZipOrigination>'. SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
             '<ZipDestination>'. $dest_zip .'</ZipDestination>' .
      '<Pounds>'. $this->item_weight[$i] .'</Pounds>' .
      '<Ounces>0</Ounces>' .
      '<Container/><Size>Regular</Size><Machinable>True</Machinable>' .
    '</Package>';
      //print "<BR> $request <BR>";
     } 
  /* else {
       $request  .= '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
                   '<Package ID="0">' .
                   '<Pounds>' . $this->item_weight . '</Pounds>' .
                   '<Ounces>0</Ounces>' .
                   '<MailType>Package</MailType>' .
	    '<GXG>' .
	    '<Length>12</Length><Width>12</Width><Height>12</Height>' .
	    '<POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag>' .
	    '</GXG>' .
	    '<ValueOfContents>50</ValueOfContents>' .
                   '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .
                   '</Package>' .
                   '</IntlRateRequest>';

       $request .= 'API=IntlRate&XML=' . urlencode($request);
     } */
}//end for i
}//end for $numgroups
$request .= '</RateV3Request>';
$requestNew = 'API=RateV3&XML=' . urlencode($request);
//print '<BR><BR>'. htmlspecialchars(urldecode($requestNew));
// exit;
     $body = '';

     if (!class_exists('httpClient')) {
       include('includes/classes/http_client.php');
     }

     $http = new httpClient();
     if ($http->Connect('production.shippingapis.com', 80)) {
       $http->addHeader('Host', 'production.shippingapis.com');
       $http->addHeader('User-Agent', 'osCommerce');
       $http->addHeader('Connection', 'Close');
       if ($http->Get('/shippingapi.dll?' . $requestNew)) $body = $http->getBody();
       $http->Disconnect();
	} else {
       return false;
     }
     $response = array();
     while (true) {
       if ($start = strpos($body, '<Package ID=')) {
         $body = substr($body, $start);
         $end = strpos($body, '</Package>');
         $response[] = substr($body, 0, $end+10);
         $body = substr($body, $end+9);
	  //print "Worked<BR><BR>";
       } else {
         //print "NO work!<BR><BR>";
	  break;

       }
     }
     $rates = array();
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
       if (sizeof($response) == '1') {
         if (ereg('<Error>', $response[0])) {
           $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
           $number = $regs[1];
           $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
           $description = $regs[1];

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

       $n = sizeof($response);
       for ($i=0; $i<$n; $i++) {
  $resp = $response[$i];
  $pos = 0;
  while (1) {
    $pos = strpos($response[$i], '<Postage', $pos);
           if ($pos === FALSE) break;
    $end = strpos($response[$i], '</Postage>', $pos);
    if ($end === FALSE) break;
    $resp = substr($response[$i], $pos, $end-$pos);
           $service = ereg('<MailService>(.*)</MailService>', $resp, $regs);
           $service = $regs[1];
           $postage = ereg('<Rate>(.*)</Rate>', $resp, $regs);
           $postage = $regs[1];
    $pos = $end;
           $rates[] = array($service => $postage);
         }
       }
     } 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;
           }
         }

         $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];

#              if (isset($this->service) && ($service != $this->service) ) {
#                continue;
#              }

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

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

   function country_list() {
     $list = array('AF' => 'Afghanistan',
                   'AL' => 'Albania',
                   'DZ' => 'Algeria',
                   'AD' => 'Andorra',
                   'AO' => 'Angola',
                   'AI' => 'Anguilla',
                   'AG' => 'Antigua and Barbuda',
                   'AR' => 'Argentina',
                   'AM' => 'Armenia',
                   'AW' => 'Aruba',
                   'AU' => 'Australia',
                   'AT' => 'Austria',
                   'AZ' => 'Azerbaijan',
                   'BS' => 'Bahamas',
                   'BH' => 'Bahrain',
                   'BD' => 'Bangladesh',
                   'BB' => 'Barbados',
                   'BY' => 'Belarus',
                   'BE' => 'Belgium',
                   'BZ' => 'Belize',
                   'BJ' => 'Benin',
                   'BM' => 'Bermuda',
                   'BT' => 'Bhutan',
                   'BO' => 'Bolivia',
                   'BA' => 'Bosnia-Herzegovina',
                   'BW' => 'Botswana',
                   'BR' => 'Brazil',
                   'VG' => 'British Virgin Islands',
                   'BN' => 'Brunei Darussalam',
                   'BG' => 'Bulgaria',
                   'BF' => 'Burkina Faso',
                   'MM' => 'Burma',
                   'BI' => 'Burundi',
                   'KH' => 'Cambodia',
                   'CM' => 'Cameroon',
                   'CA' => 'Canada',
                   'CV' => 'Cape Verde',
                   'KY' => 'Cayman Islands',
                   'CF' => 'Central African Republic',
                   'TD' => 'Chad',
                   'CL' => 'Chile',
                   'CN' => 'China',
                   'CX' => 'Christmas Island (Australia)',
                   'CC' => 'Cocos Island (Australia)',
                   'CO' => 'Colombia',
                   'KM' => 'Comoros',
                   'CG' => 'Congo (Brazzaville),Republic of the',
                   'ZR' => 'Congo, Democratic Republic of the',
                   'CK' => 'Cook Islands (New Zealand)',
                   'CR' => 'Costa Rica',
                   'CI' => 'Cote d\'Ivoire (Ivory Coast)',
                   'HR' => 'Croatia',
                   'CU' => 'Cuba',
                   'CY' => 'Cyprus',
                   'CZ' => 'Czech Republic',
                   'DK' => 'Denmark',
                   'DJ' => 'Djibouti',
                   'DM' => 'Dominica',
                   'DO' => 'Dominican Republic',
                   'TP' => 'East Timor (Indonesia)',
                   'EC' => 'Ecuador',
                   'EG' => 'Egypt',
                   'SV' => 'El Salvador',
                   'GQ' => 'Equatorial Guinea',
                   'ER' => 'Eritrea',
                   'EE' => 'Estonia',
                   'ET' => 'Ethiopia',
                   'FK' => 'Falkland Islands',
                   'FO' => 'Faroe Islands',
                   'FJ' => 'Fiji',
                   'FI' => 'Finland',
                   'FR' => 'France',
                   'GF' => 'French Guiana',
                   'PF' => 'French Polynesia',
                   'GA' => 'Gabon',
                   'GM' => 'Gambia',
                   'GE' => 'Georgia, Republic of',
                   'DE' => 'Germany',
                   'GH' => 'Ghana',
                   'GI' => 'Gibraltar',
                   'GB' => 'Great Britain and Northern Ireland',
                   'GR' => 'Greece',
                   'GL' => 'Greenland',
                   'GD' => 'Grenada',
                   'GP' => 'Guadeloupe',
                   'GT' => 'Guatemala',
                   'GN' => 'Guinea',
                   'GW' => 'Guinea-Bissau',
                   'GY' => 'Guyana',
                   'HT' => 'Haiti',
                   'HN' => 'Honduras',
                   'HK' => 'Hong Kong',
                   'HU' => 'Hungary',
                   'IS' => 'Iceland',
                   'IN' => 'India',
                   'ID' => 'Indonesia',
                   'IR' => 'Iran',
                   'IQ' => 'Iraq',
                   'IE' => 'Ireland',
                   'IL' => 'Israel',
                   'IT' => 'Italy',
                   'JM' => 'Jamaica',
                   'JP' => 'Japan',
                   'JO' => 'Jordan',
                   'KZ' => 'Kazakhstan',
                   'KE' => 'Kenya',
                   'KI' => 'Kiribati',
                   'KW' => 'Kuwait',
                   'KG' => 'Kyrgyzstan',
                   'LA' => 'Laos',
                   'LV' => 'Latvia',
                   'LB' => 'Lebanon',
                   'LS' => 'Lesotho',
                   'LR' => 'Liberia',
                   'LY' => 'Libya',
                   'LI' => 'Liechtenstein',
                   'LT' => 'Lithuania',
                   'LU' => 'Luxembourg',
                   'MO' => 'Macao',
                   'MK' => 'Macedonia, Republic of',
                   'MG' => 'Madagascar',
                   'MW' => 'Malawi',
                   'MY' => 'Malaysia',
                   'MV' => 'Maldives',
                   'ML' => 'Mali',
                   'MT' => 'Malta',
                   'MQ' => 'Martinique',
                   'MR' => 'Mauritania',
                   'MU' => 'Mauritius',
                   'YT' => 'Mayotte (France)',
                   'MX' => 'Mexico',
                   'MD' => 'Moldova',
                   'MC' => 'Monaco (France)',
                   'MN' => 'Mongolia',
                   'MS' => 'Montserrat',
                   'MA' => 'Morocco',
                   'MZ' => 'Mozambique',
                   'NA' => 'Namibia',
                   'NR' => 'Nauru',
                   'NP' => 'Nepal',
                   'NL' => 'Netherlands',
                   'AN' => 'Netherlands Antilles',
                   'NC' => 'New Caledonia',
                   'NZ' => 'New Zealand',
                   'NI' => 'Nicaragua',
                   'NE' => 'Niger',
                   'NG' => 'Nigeria',
                   'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',
                   'NO' => 'Norway',
                   'OM' => 'Oman',
                   'PK' => 'Pakistan',
                   'PA' => 'Panama',
                   'PG' => 'Papua New Guinea',
                   'PY' => 'Paraguay',
                   'PE' => 'Peru',
                   'PH' => 'Philippines',
                   'PN' => 'Pitcairn Island',
                   'PL' => 'Poland',
                   'PT' => 'Portugal',
                   'QA' => 'Qatar',
                   'RE' => 'Reunion',
                   'RO' => 'Romania',
                   'RU' => 'Russia',
                   'RW' => 'Rwanda',
                   'SH' => 'Saint Helena',
                   'KN' => 'Saint Kitts (St. Christopher and Nevis)',
                   'LC' => 'Saint Lucia',
                   'PM' => 'Saint Pierre and Miquelon',
                   'VC' => 'Saint Vincent and the Grenadines',
                   'SM' => 'San Marino',
                   'ST' => 'Sao Tome and Principe',
                   'SA' => 'Saudi Arabia',
                   'SN' => 'Senegal',
                   'YU' => 'Serbia-Montenegro',
                   'SC' => 'Seychelles',
                   'SL' => 'Sierra Leone',
                   'SG' => 'Singapore',
                   'SK' => 'Slovak Republic',
                   'SI' => 'Slovenia',
                   'SB' => 'Solomon Islands',
                   'SO' => 'Somalia',
                   'ZA' => 'South Africa',
                   'GS' => 'South Georgia (Falkland Islands)',
                   'KR' => 'South Korea (Korea, Republic of)',
                   'ES' => 'Spain',
                   'LK' => 'Sri Lanka',
                   'SD' => 'Sudan',
                   'SR' => 'Suriname',
                   'SZ' => 'Swaziland',
                   'SE' => 'Sweden',
                   'CH' => 'Switzerland',
                   'SY' => 'Syrian Arab Republic',
                   'TW' => 'Taiwan',
                   'TJ' => 'Tajikistan',
                   'TZ' => 'Tanzania',
                   'TH' => 'Thailand',
                   'TG' => 'Togo',
                   'TK' => 'Tokelau (Union) Group (Western Samoa)',
                   'TO' => 'Tonga',
                   'TT' => 'Trinidad and Tobago',
                   'TN' => 'Tunisia',
                   'TR' => 'Turkey',
                   'TM' => 'Turkmenistan',
                   'TC' => 'Turks and Caicos Islands',
                   'TV' => 'Tuvalu',
                   'UG' => 'Uganda',
                   'UA' => 'Ukraine',
                   'AE' => 'United Arab Emirates',
                   'UY' => 'Uruguay',
                   'UZ' => 'Uzbekistan',
                   'VU' => 'Vanuatu',
                   'VA' => 'Vatican City',
                   'VE' => 'Venezuela',
                   'VN' => 'Vietnam',
                   'WF' => 'Wallis and Futuna Islands',
                   'WS' => 'Western Samoa',
                   'YE' => 'Yemen',
                   'ZM' => 'Zambia',
                   'ZW' => 'Zimbabwe');

     return $list;
   }
 }
?>


 

The main changes were with Function _GetQuote() which changed the call to USPS and Function quote which processed the data returned from USPS into the options for the user.

 

Hope this helps someone!

Jen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×