The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Zip Code Validation

jaushmanjaushman Member
in Bugs & Feature Requests edited January 2011
We've recently discovered some issues at our fulfillment house with invalid zip codes and I wanted to run it by you guys to get your thoughts. We are using both FedEx and UPS as shipping carriers with free domestic shipping via UPS. I suspect that the free shipping option is masking errors returned by the carriers.

For example, a customer recently used a zip code of 'CA90045'. My investigation shows that with free domestic shipping turned on there are no errors returned and the only shipping option a customer receives is 'free shipping'.

However, with free shipping turned off the correct error message is displayed in the shipping section as:
FedEx Error: Destination postal code missing or invalid.
UPS Error: The postal code CA900 is invalid for CA United States.


It would certainly be our preference that if errors like this are returned from the carriers that the customer not be allowed to continue with checkout. I thought about trying to throw together a simple zip code validation script but then realized that will get much trickier with our International customers. Any ideas?

EDIT:
Thinking this through I realize this will only affect domestic shipping as those are the only addresses that have a free shipping option. The javascript validation may be an option then. First, I've got to get some coffee. :D
Comments
  • lukeluke FoxyCart Team
    We've been looking into some address validation stuff along with some tax improvements, but it may not happen anytime soon. Your best bet may be to come up with a custom solution for now to meet your needs. Please let us know how it goes and feel free to post back anything you come up with.

    We probably should be validating US and Canadian postal codes at the very least... but... man, so much to do. :)
  • jaushmanjaushman Member
    edited January 2011
    I had to do a couple of things to get this working. It's not sexy and it's not supported but it does work...for us.

    [ulist]
    [li]Override FC.checkout.updateShipping[/li]
    [li]Force multiship to "-1" since this store doesn't allow multiship and because I ran out of project hours. This is done via
    var multiship = -1;
    
    at the top of the custom function.[/li]
    [li]Analyze the data returned by the $.getJSON request one step further than what currently exists. To validate U.S. zip codes I decided to look for 2 things - The ship to country is "US" and the length of the shipping options returned by the AJAX request is 1 - which indicates that the only option returned is "free shipping". This allows me to do more than just zip/postal code validation since FedEx/UPS could return errors for other missteps in address entry. You can see this update in lines 102 to 109 in the pastie below.[/li]
    [/ulist]

    Obviously this solution won't work for every store. I did want to share it in case someone else needed a jumping off point.

    The core of the issue, as far as I can see, is that the AJAX request for shipping methods is always masking errors raised by UPS/FedEx when the store has "free shipping" for domestic addresses. I know there are many more important issues on the table...just wanted to clarify the bug I was seeing.

    Here's what I ended up - http://pastie.org/private/6pbicyjkuqveo1srq4ww
  • lukeluke FoxyCart Team
    Thanks for posting!
Sign In or Register to comment.