US 9 Digit Postal Code: USPS Shipping Module

  • Posts: 45
  • Thank you received: 1
12 years 2 months ago #40901

I have a small problem with the USPS shipping module? I noticed that the hyphen (-) in the US nine digit postal code causes the shipping module not to recognize it. For example postal code

19438-1059 causes a "no shipping method available error"

However if you enter the postal code without the hyphen like this 19438 1094 it works. Most people will enter the 9 digit postal code with the hyphen so I think the USPS Shipping Modules needs to be able to handle the presence of it.

Thank you,

Paul

Please Log in or Create an account to join the conversation.

  • Posts: 81677
  • Thank you received: 13100
  • MODERATOR
12 years 2 months ago #41049

Hi,

Please replace the code:
$parcel->Pickup_Postcode = substr(trim(@$rate->shipping_params->post_code),0,6);
$parcel->Destination_Postcode = substr(trim($order->shipping_address->address_post_code),0,6);

by:
$parcel->Pickup_Postcode = substr(preg_replace('#[^a-z0-9]#i','',@$rate->shipping_params->post_code),0,6);
$parcel->Destination_Postcode = substr(preg_replace('#[^a-z0-9]#i','',$order->shipping_address->address_post_code),0,6);

in the file plugins/hikashopshipping/usps.php and that should do it.

Last edit: 12 years 2 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 1
12 years 2 months ago #41064

Nicolas,

I just made the change now I get a fatal error. Specifically:

Fatal error: Call to undefined function preg_replace_() in /html/erielack/test-dev/joomla/plugins/hikashopshipping/usps/usps.php on line 113

Here is the screen shot of the code. I commented out the original and cut/pasted you code as directed.

I am running PHP 5.3.9

Attachments:
Last edit: 12 years 2 months ago by ELHS. Reason: Forgot PHP version

Please Log in or Create an account to join the conversation.

  • Posts: 81677
  • Thank you received: 13100
  • MODERATOR
12 years 2 months ago #41065

Sorry it's a typo.

it should be preg_replace and not preg_replace_
I've corrected the code in my previous post.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 1
12 years 2 months ago #41067

Ok, I fixed the typ0 and now the plugin doesn't recognize the postal code with or without the hyphen. It is getting late here and its really early in the morning for you. This can wait until tomorrow as I am not in production nor do I have a strict deadline to meet.

Thank you,

Paul

Please Log in or Create an account to join the conversation.

  • Posts: 81677
  • Thank you received: 13100
  • MODERATOR
12 years 2 months ago #41195

Make sure that you replace both preg_replace_ in the code and not only the first one.
I don't see why that code would not work.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 1
12 years 2 months ago #41251

Nicolas,

Here is the code:

$query = 'SELECT currency_id FROM '.hikashop_table('currency').' WHERE currency_code=\'USD\'';
					$db =& JFactory::getDBO();
					$db->setQuery($query);
					$currency = $db->loadResult();
					$parcel = null;
                                        $parcel->Country = $order->shipping_address_full->shipping_address->address_country->zone_code_2;
					/* Per Nicolas at Hikara Software 02/25/2012
					* $parcel->Pickup_Postcode = substr(trim(@$rate->shipping_params->post_code),0,6);
					* $parcel->Destination_Postcode = substr(trim($order->shipping_address->address_post_code),0,6);
					*PFC added the following on 02/25/2012
					*/
					$parcel->Pickup_Postcode = substr(preg_replace('#[^a-z0-9]#i','',@$rate->shipping_params->post_code),0,6);
					$parcel->Destination_Postcode = substr(preg_replace('#[^a-z0-9]#i','',$order->shipping_address->address_post_code),0,6);
					$parcel->Length=15;
					$parcel->Width=15;
					$parcel->Height=15;
					$parcel->Quantity=1;
                                        $parcel->Weight=$package_weight;
                                        //dump($parcel->Weight);

Please Log in or Create an account to join the conversation.

  • Posts: 81677
  • Thank you received: 13100
  • MODERATOR
12 years 2 months ago #41256

I checked online and normally only the first 5 digits of the post code are sent to USPS. Maybe it comes from that (we didn't made the plugin which was done by another developer, so I'm just guessing to help you based on what I could find online) ?

Try like that:
$parcel->Pickup_Postcode = substr(preg_replace('#[^a-z0-9]#i','',@$rate->shipping_params->post_code),0,5);
$parcel->Destination_Postcode = substr(preg_replace('#[^a-z0-9]#i','',$order->shipping_address->address_post_code),0,5);

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 1
12 years 2 months ago #41477

That fixed the problem. I originally try to contact the USPS plugin provider however a dead email address is listed in the code comments.

Thank you

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds
Powered by Kunena Forum