VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Shipping VM 1.1 => UPS VM 1 => Topic started by: navdeep on February 14, 2010, 16:58:02 PM

Title: Not to Ship on P.O Boxes
Post by: navdeep on February 14, 2010, 16:58:02 PM
Hello Virtuemart Developers,

I need your help... i dont want to accept orders for P.O Boxes.. in simple i need a prompt error message when some one
- Add New Shipping Address
- Default (Use same as Billing Address)
- Update Existing Shipping Address

i found a function in ps_checkout.php
        function validate_shipto(&$d) {
//TODO to be implemented
        }


Something is missing...i want to validate shipping address against PO Box

i have already function to do this..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;
  }
}
Title: Re: Not to Ship on P.O Boxes
Post by: lowmips on February 14, 2010, 23:46:05 PM
Catch the Billing address in ps_user.php (look at the validation methods, add your code there).
Catch the Shipping addresses in ps_user_address.php (again, add your code to the validation methods).

use the global $vmLogger to throw an error, warning, whatever like this:
$vmLogger->err('Sorry, we do not ship to P.O. addresses');

-Reggie
Title: Re: Not to Ship on P.O Boxes
Post by: navdeep on February 15, 2010, 12:16:50 PM
 :) Thanks lowmips for you kind help...But Problem still presists  :'(
Some users have already Addresses of PO Boxes... So i need validation during Step 1 Checkout Process. Please Help
Title: Re: Not to Ship on P.O Boxes
Post by: nicodesigns on March 17, 2010, 23:51:52 PM
For the files:
administrator/components/com_virtuemart/classes/ps_user.php (line 128)
administrator/components/com_virtuemart/classes/ps_user_address.php (line 104)

I inserted the following code:

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)) {
  $vmLogger->err('Sorry, we do not ship to P.O. Boxes');
    return true;
  }
  else {
    return false;
  }
}

I went to add a new shipping address using a PO Box and it still accepted it.
What did I do incorrectly?  ???

Thanks!
Title: Re: Not to Ship on P.O Boxes
Post by: orchid1 on March 24, 2010, 21:25:02 PM
does any one know where to insert the code above?
I inserted the function into the code but I am not sure where to call the function or what variable I pass it. I recognize that I have to pass the address but I am not sure what VM calls that variable or on what line to make the call to the function
for instance where would I write "func_is_postal_box($vm_address);"
thus triggering the validation function to check for PO BOX?

I have the code for the regular expression per the previous post I'm just not sure where to make the call to it.

Anybody have 5 minutes to post back I would be happy to make a small contribution to your paypal account.
Thanks

Title: Re: Not to Ship on P.O Boxes
Post by: nicodesigns on March 24, 2010, 21:29:45 PM
Hi Orchid,

I hired Lowmips to fix this with FedEx.  Perhaps he can help you too.
Title: Re: Not to Ship on P.O Boxes
Post by: cchrisgates on July 26, 2011, 21:23:24 PM
Short of hiring someone to add this function, has anyone figured out a solution.  Seems this should be implemented in the shipping modules/store configuration