4

One of our client's shipper allow shipping to only specific ZIP codes. So we do have list of allowed ZIP codes.

We want to restrict user to place order on checkout page or cart page if shipping address ZIP code in not from allowed ZIP codes.

How we can do this?

is there any already existing solution for this?

  • 1
    use controller_action_predispatch_checkout_onepage_saveBilling and controller_action_predispatch_checkout_onepage_saveShipping events and write a php function in the observer to compare the zipcode to your existing list and proceed if valid or throw an exception if invalid, which will not allow the user to proceed further. I'll post this as answer with code later, meanwhile try this way. – Shathish Aug 29 '13 at 7:02
  • thanks Shathish. overriding controller you mention will do this. if you finish code as you said please add to answer. thanks in advance. – Sandesh Aug 30 '13 at 7:07
  • Sure you can use controller rewrite as Sander suggested, I thought I would give a code which never even disturbs the core process. But unfortunately I don't remember how I shown that exception in onepage checkout :( – Shathish Aug 30 '13 at 8:03
5

The cleanest way to do this is to add extra validation functions in the Onepage Controller, the shipping and billing actions.

Take a look at this article by Inchoo on Magento validation. Also, if possible, add the validation to the javascript validation library so no form submit is required.

This custom validation function could test the user submitted zipcode against your list of allowed ones and return false if it doesn't match

  • I think adding the validation to client side script is not advisable as user may modify the script or just the class to place the order from a different zip code. It'll be a better solution to take care of this validation using an observer. – Shathish Aug 29 '13 at 6:57
  • It's never advisable to depend solely on Javascript. That is the reason I started my answer with adding validation to the Controller. However, the javascript check provides much nicer error feedback so it's advisable to implement that as well. Which Observer do you suggest to use? – Sander Mangel Aug 29 '13 at 7:06
  • agreed! Actually I used a similar way (I left on the commment to the question) to accomplish the same task long back, where I wasn't allowed to override onepagecontroller. I'm searchin for that code to post as the answer. – Shathish Aug 29 '13 at 7:11
  • Ah I see it now. When you post your code you'll have my upvote – Sander Mangel Aug 29 '13 at 7:27
2

You can set up table rate shipping with the valid ZIP codes and shipping prices just using default Magento. If a user enters a ZIP code that doesn't match it will just display a "No shipping methods available" message in the checkout, this message can then be changed through your translation files to be clearer, e.g "Shipping is not available to this ZIP code, please see our shipping policy for available areas".

1

You can try shipping restriction extension from Amasty http://amasty.com/shipping-restrictions.html and check if it fulfill your requirements.

1

Sounds like you could use this extension: http://www.magentocommerce.com/magento-connect/restrict-check-cod-payment-method-for-zip-pin-codes-24717.html

Using this extension, you can also let your users check COD availability right from the product page!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.