Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Disable UPS and FedEx for P.O. Boxes

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 01-07-2010, 08:32 AM
 
exsecror exsecror is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,284
 

Post Disable UPS and FedEx for P.O. Boxes

Disclaimer: I am not responsible for any failed or lost orders due to the implementation of this modification. It is up to you to fully test it on a staging system before deploying it to production.

This tends to be a relatively annoying issue for a lot of people. A customer order's and item (usually a rather large item) and has it shipped to a P.O. Box only to have UPS or FedEx reject the delivery. While it is true they can ship to Post Office Boxes not all of them are either accessible to UPS/FedEx or they are too small for the parcel in question. Unfortunately X-Cart by default gives no option for people to disable shipping via these methods to those addresses.

We've been using this modification for the past 2 years (though with slightly different logic) so I've decided to strip out the code sealed under NDA and share the open version with everyone else.

Note: The following modification was written around X-Cart versions 4.1 and 4.2 and has not been tested for 4.3.

The first file you need to modify is shipping/myshipper.php. Open the file and at the very bottom of the code add the following function:

PHP Code:
// {{{ func_is_postal_box()
/**
 * This function checks to see if the customer's
 * shipping address is a United States Post Office
 * Box.
 *
 * @param string $address Customer's Street Address
 * @return boolean true if post office box; false if not
 */
function func_is_postal_box($address) {
  
$postalBoxRegex '/^([pP]{1}(.*?)[oO]{1}(.*?))?([bB][oO]?[xX])(\s+)([0-9]+)/iD';

  @
preg_match($postalBoxRegextrim($address), $isPostalBox);

  if (
is_array($isPostalBox) && (count($isPostalBox) > 0)) {
    return 
true;
  }
  else {
    return 
false;
  }
}
// }}} 

Next you will need to edit two files, shipping/mod_UPS.php and depending if you're using X-Cart 4.1 or 4.2 either shipping/mod_FEDEX.php (4.2) or shipping/mod_FEDEX_direct.php (4.1)

shipping/mod_UPS.php:

After:
PHP Code:
if (!$UPS_FOUND)
    return; 

Add:
PHP Code:
/* Check for the existance of a P.O. Box Address */
if (func_is_postal_box($userinfo['s_address'])) return; 

shipping/mod_FEDEX.php (4.2) or shipping/mod_FEDEX_direct.php (4.1)

After:
PHP Code:
if (!$FEDEX_FOUND)
    return; 

Add:
PHP Code:
/* Check for the existance of a P.O. Box Address */
if (func_is_postal_box($userinfo['s_address'])) return; 

Once you have made these modifications truncate the xcart_shipping_cache table and you should be good to go. This will disable UPS and FedEx for any address that is considered a P.O. Box by the regular expression (this expression has been thoroughly tested against thousands of customers who tried to get around it)

Enjoy
Reply With Quote

The following 3 users thank exsecror for this useful post:
cflsystems (01-07-2010), Jayk (01-07-2010), mrerotic (03-21-2011)
  #2  
Old 01-07-2010, 12:14 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Disable UPS and FedEx for P.O. Boxes

This should really be in the core code of xcart. Thanks Alan
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 01-08-2010, 03:51 AM
 
exsecror exsecror is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,284
 

Default Re: Disable UPS and FedEx for P.O. Boxes

Quote:
Originally Posted by cflsystems
This should really be in the core code of xcart. Thanks Alan

I agree, I also have similar procedures for blocking real-time shipping methods to zones (which it cannot do by default) and I also patched them to pass the customer's shipping address in the lookup for accurate rates (something else it should be doing by default but isn't)
Reply With Quote
  #4  
Old 03-11-2010, 01:37 PM
 
DocOrtho DocOrtho is offline
 

Newbie
  
Join Date: Jan 2007
Posts: 5
 

Default Re: Disable UPS and FedEx for P.O. Boxes

I have flat rates and don't use real time calculations. It was just as easy to edit the shipping/shipping.php file:

Around line 288
Code:
if (!$enable_shipping || $config["Shipping"]["realtime_shipping"] != "Y") { # # Get ALL shipping methods according to the conditions (W/O real time) # $shipping = func_query("SELECT * FROM $sql_tbl[shipping] WHERE active='Y' $destination_condition $weight_condition ORDER BY orderby");
Change to:
Code:
if (!$enable_shipping || $config["Shipping"]["realtime_shipping"] != "Y") { # # Get ALL shipping methods according to the conditions (W/O real time) # // {{{ func_is_postal_box() /** * This function checks to see if the customer's * shipping address is a United States Post Office * Box. * * @param string $address Customer's Street Address * @return boolean true if post office box; false if not */ function func_is_postal_box($address) { $postalBoxRegex = '/^([pP]{1}(.*?)[oO]{1}(.*?))?([bB][oO]?[xX])(\s+)([0-9]+)/iD'; @preg_match($postalBoxRegex, trim($address), $isPostalBox); if (is_array($isPostalBox) && (count($isPostalBox) > 0)) { return true; } else { return false; } } // }}} if (func_is_postal_box($userinfo['s_address'])){ $shipping = func_query("SELECT * FROM $sql_tbl[shipping] WHERE active='Y' AND code='USPS' $destination_condition $weight_condition ORDER BY orderby"); }else{ $shipping = func_query("SELECT * FROM $sql_tbl[shipping] WHERE active='Y' $destination_condition $weight_condition ORDER BY orderby"); }
__________________
X-Cart v4.3
Reply With Quote
  #5  
Old 03-10-2011, 02:25 PM
 
Kiss Kiss is offline
 

Member
  
Join Date: Nov 2010
Posts: 15
 

Default Re: Disable UPS and FedEx for P.O. Boxes

I implemented this code and it works properly. The only issue I have since I am using one page checkout in 4.4 2, I have to refresh a screen in order to display if shipping is allowed. Any advise? Also how can I display a message indicatting that we do not ship to P.O. Boxes ?

Thanks,
Fred.
__________________
x-cart Gold 4.4

snow cone syrup
wizard of oz
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:44 AM.

   

 
X-Cart forums © 2001-2020