Jump to content



Latest News: (loading..)

- - - - -

USPS Shipping Labels


  • Please log in to reply
39 replies to this topic

#21   Avec

Avec
  • Members
  • 817 posts
  • Real Name:Jeffrey Todd
  • Gender:Male

Posted 20 March 2012 - 10:05 PM

View Postblueedge, on 20 March 2012 - 03:07 PM, said:

Well, I'm making progress. By including <? include('uspslabelfix.php');?>, the label function now works. However, like the poster above, all of the info is imported into the USPS form except for the state.

Where did you add this?  Which file and where in the file.

Did you get it all working with these changes?  It might be useful to put together a more informative release to specify all the information needed including the exact changes (again, file and location).

Thanks for everyone's work on this.

#22   vjwebb

vjwebb
  • Community Sponsor
  • 52 posts
  • Real Name:V J Webb
  • Gender:Female
  • Location:Fresno, CA

Posted 21 March 2012 - 12:38 AM

Can someone please tell me where in orders.php that I put the following line of code.

<?PHP include('uspslabelfix.php');?>

Wes said it goes just before the </td>  but I must not be finding the right one, because I am getting an error.

Thank you and a grateful thanks to Wes for solving the problem.
-- A ship in a harbor is safe, but that is not a ships ultimate purpose.

#23   Wes_SFLL

Wes_SFLL
  • Members
  • 10 posts
  • Real Name:Wes
  • Gender:Male

Posted 21 March 2012 - 02:32 AM

Alright in orders.php under your admin folder find the old code for usps label shipping which should look like....

<a href="' . tep_href_link(FILENAME_ORDERS_USPS_SHIP, 'oID=' . $HTTP_GET_VARS['oID'])

after that entire line but before the next occurrence of </td> add this:

<? include('uspslabelfix.php');?>

OR (the same thing can be done by adding include('uspslabelfix.php'); just before the ?> at the end of the line  )

What you are doing is adding a button that has a bunch of hidden form elements to your orders.php file...

Make sure to upload uspslabelfix.php from the contribution at http://addons.oscommerce.com/info/1498 to your admin folder.

Doing it this way over replacing the filename for the usps label contribution is great just in case they switch back to the old way...

#24   imagixx

imagixx
  • Members
  • 98 posts
  • Real Name:Martin B.
  • Gender:Male

Posted 21 March 2012 - 04:34 AM

OK.  Why not just name your fix file usps_ship.php and replace the current usps_ship.php?  Of cpourse I tried that and the only carry-over is the oID/Reference Number.  Why arenlt the other fields populating properly?

#25   imagixx

imagixx
  • Members
  • 98 posts
  • Real Name:Martin B.
  • Gender:Male

Posted 21 March 2012 - 04:55 AM

OK, just add to uspslabelfix.php below  global $db;

require('includes/application_top.php');
$oID = (int)tep_db_prepare_input($HTTP_GET_VARS['oID']);
include(DIR_WS_CLASSES . 'order.php');
$order = new order($oID);

rename uspslabelfix.php usps_ship.php, drop into your admin folder, and you got the imported data.

Now, to try my meager skills at fixing the two letter state.

#26   imagixx

imagixx
  • Members
  • 98 posts
  • Real Name:Martin B.
  • Gender:Male

Posted 21 March 2012 - 05:53 AM

Fixing 2 digit state.

Add below  //directory where all support files are

//Gets the return & billing address two digit state code
$shipping_zone_query = tep_db_query("select z.zone_code from " . TABLE_ZONES . " z, " . TABLE_COUNTRIES . " c where zone_name = '" . $order->delivery['state'] . "' AND c.countries_name = '" . $order->delivery['country'] . "' AND c.countries_id = z.zone_country_id");
$shipping_zone = tep_db_fetch_array($shipping_zone_query);
$shipping_zone_code = ($shipping_zone['zone_code'] == '' ? $order->delivery['state'] : $shipping_zone['zone_code']);  // if the query result was empty, then use the state name
if ($order->billing['state'] == $order->delivery['state']) {  // if billing and shipping states are the same, then we can save a query
  $billing_zone_code = $shipping_zone_code;
  } else {
  $billing_zone_query = tep_db_query("select z.zone_code from " . TABLE_ZONES . " z, " . TABLE_COUNTRIES . " c where z.zone_name = '" . $order->billing['state'] . "' AND c.countries_name = '" . $order->billing['country'] . "' AND c.countries_id = z.zone_country_id");
  $billing_zone = tep_db_fetch_array($billing_zone_query);
  $billing_zone_code = ($billing_zone['zone_code'] == '' ? $order->billing['state'] : $billing_zone['zone_code']); // if the query result was empty, then use the state name
  }

Replace
<input type="hidden" name="form.deliveryState" value= "<?php echo $order->delivery['state'];?>" id="stateTo">

With
//State
<input type="hidden" name="form.deliveryState" value= "<?php echo $shipping_zone_code;?>" id="stateTo">

I haven't figured out the result if country is not us.  But this fixes the immediate problem.

#27   imagixx

imagixx
  • Members
  • 98 posts
  • Real Name:Martin B.
  • Gender:Male

Posted 21 March 2012 - 06:29 AM

OK, State fixed.  (may need changfes for non-US country).  new usps_ship.php file is available for download at:

http://www.oscommerce.com/community/contributions,1498

It works, but the file should be really cleaned up by someone who really knows whgat they're doing.

#28   vjwebb

vjwebb
  • Community Sponsor
  • 52 posts
  • Real Name:V J Webb
  • Gender:Female
  • Location:Fresno, CA

Posted 21 March 2012 - 07:18 PM

I have it working although it is not picking up my Company Name (it used to).  I think the problem may be that my USPS account is personal and not business.  I have sent them an email asking how to fix the problem.  I can go into edit mode after the fields are filled in and add the name but that is time consuming.  At least I don't have to enter the shipping address.

I would like to thank everyone for all the hard work.  I still can't believe that our tax dollars are being used to change the shipping page into a frilly hard to read page.  No wonder the post office is losing money.
-- A ship in a harbor is safe, but that is not a ships ultimate purpose.

#29   vjwebb

vjwebb
  • Community Sponsor
  • 52 posts
  • Real Name:V J Webb
  • Gender:Female
  • Location:Fresno, CA

Posted 21 March 2012 - 11:02 PM

Just in case anyone else is having a problem with company name.  I fixed the company name.  I set up a new account with USPS that is flagged as business and it let me add a Company Name.  The old version of usps_php picked up the return address values from the configuration file.  The new version is using the info on the USPS account.
-- A ship in a harbor is safe, but that is not a ships ultimate purpose.

#30   Ghost0

Ghost0
  • Members
  • 1 posts
  • Real Name:Jim Welch

Posted 22 March 2012 - 02:16 AM

Hello all, new to this forum and had the same issue that the OP had with our OSC site. I had our web developer help us and this is the fix he came up with. We are using zone rates so some of the previous posters may be using a different code. It sure was a PITA no thanks to USPS.Attached File  USPS Fix for OSCommerce.txt   1.98K   11 downloads

#31   fqstore

fqstore
  • Members
  • 22 posts
  • Real Name:Don R
  • Gender:Male

Posted 22 March 2012 - 03:52 AM

Wow, I am not live on the web.  I was considering using this module but I think I will just use click and ship and Paypal.  Easy enough for me.  The only drawback to Paypal is the service charge.  But it is worth not having the headaches.

#32   imagixx

imagixx
  • Members
  • 98 posts
  • Real Name:Martin B.
  • Gender:Male

Posted 22 March 2012 - 05:19 PM

Actually, it works like a charm.  The change was required by a USPS design change.

#33   krdito

krdito
  • Members
  • 67 posts
  • Real Name:Krdito
  • Gender:Female

Posted 22 March 2012 - 05:23 PM

Thanks to all who worked on this fix!  Your efforts are greatly appreciated!

#34   apache510

apache510
  • Members
  • 35 posts
  • Real Name:Alfred Pacheco
  • Gender:Male
  • Location:Washington State

Posted 22 March 2012 - 07:27 PM

I downloaded the update and everything works except the first and last name in the delivery address is not being populated.  At least I have all the other information going through.  Anyone have a fix for this?

#35   vjwebb

vjwebb
  • Community Sponsor
  • 52 posts
  • Real Name:V J Webb
  • Gender:Female
  • Location:Fresno, CA

Posted 22 March 2012 - 08:37 PM

View Postapache510, on 22 March 2012 - 07:27 PM, said:

I downloaded the update and everything works except the first and last name in the delivery address is not being populated.  At least I have all the other information going through.  Anyone have a fix for this?

around line 149 in usps_ship.php find:
$arr = explode(" ", $order->customer['name'], 2);

And replace it with this:
$arr = explode(" ", $order->delivery['name'], 2);

It was using the customer name instead of the delivery name.  If they are the same, you don't see the problem.  Thanks for the catch.
-- A ship in a harbor is safe, but that is not a ships ultimate purpose.

#36   apache510

apache510
  • Members
  • 35 posts
  • Real Name:Alfred Pacheco
  • Gender:Male
  • Location:Washington State

Posted 22 March 2012 - 10:08 PM

Tried it but still no first or last name sent to the form.  Here is what I have in that area:


$arr = explode(" ", $order->delivery['name'], 2);
   $myFirstName = $arr[0];
   $myLastName = $arr[1];
   $myFirstName = ucfirst(strtolower($myFirstName));
   if(strlen($myFirstName) < 3 ){
  $myFirstName = substr($order->customer['name'], 0, strrpos( $order->customer['name'], ' ') );
   }

everything else is exported to the USPS form correctly.

#37   apache510

apache510
  • Members
  • 35 posts
  • Real Name:Alfred Pacheco
  • Gender:Male
  • Location:Washington State

Posted 22 March 2012 - 10:22 PM

Here is a bit more code where I think the problem is.

<?
$arr = explode(" ", $order->delivery['name'], 2);
   $myFirstName = $arr[0];
   $myLastName = $arr[1];
   $myFirstName = ucfirst(strtolower($myFirstName));
   if(strlen($myFirstName) < 3 ){
  $myFirstName = substr($order->customer['name'], 0, strrpos( $order->customer['name'], ' ') );
   }

?>
<input type="hidden" name="form.deliveryFirstName" value="<?php echo $myFirstName; ?>" id="tNameFirstTo">
<input type="hidden" name="form.deliveryLastName" value="<?php echo $myLastName; ?>" id="tNameLastTo">
<input type="hidden" name="form.deliveryCompanyName" value="<?php echo $order->delivery['company']; ?>" id="tCompanyTo">
<input type="hidden" name="form.deliveryAddressOne" value="<?php echo $order->delivery['street_address']; ?>" id="tAddress1To">
<input type="hidden" name="form.deliveryAddressTwo" value="<?php echo $order->delivery['suburb']; ?>" id="tAddress2To">
<input type="hidden" name="form.deliveryCity" value="<?php echo $order->delivery['city']; ?>" id="tCityTo">

#38   apache510

apache510
  • Members
  • 35 posts
  • Real Name:Alfred Pacheco
  • Gender:Male
  • Location:Washington State

Posted 22 March 2012 - 11:57 PM

Ignore the above two post from me.  The problem is with my test server.  It works perfectly with my live site.  Not sure why the difference.

#39   dkinzer

dkinzer
  • Members
  • 18 posts
  • Real Name:Don Kinzer
  • Location:Portland, OR USA

Posted 28 March 2012 - 09:12 PM

View Postapache510, on 22 March 2012 - 11:57 PM, said:

It works perfectly with my live site.  Not sure why the difference.
For rare cases, you'll also need to make this change, too:
// change this
$myFirstName = substr($order->customer['name'], 0, strrpos( $order->customer['name'], ' ') );

// to this
$myFirstName = substr($order->delivery['name'], 0, strrpos( $order->delivery['name'], ' ') );

Don
Portland, OR USA

#40   dkinzer

dkinzer
  • Members
  • 18 posts
  • Real Name:Don Kinzer
  • Location:Portland, OR USA

Posted 29 March 2012 - 05:23 PM

I changed the code for handling short first names like "J. Robert Fox".  The existing code generated "J. Robert" for the first name and "Robert Fox" for the last name.

Around line 158:
$arr = explode(" ", $order->delivery['name'], 2);
$myFirstName = $arr[0];
$myLastName = $arr[1];
$myFirstName = ucfirst(strtolower($myFirstName));
if (strlen($myFirstName) < 3 ){
   // short first name, see if last name has multiple parts
   $arr = explode(" ", $myLastName, 2);
   if (strlen($arr[1])) {
	  $myFirstName .= ' ' . $arr[0];
	  $myLastName = $arr[1];
   }
}
Even this code, however, isn't going to work well with a name like "J. Roberts Jr." but I'm not going to fuss with it any more right now.
Don
Portland, OR USA