A key feature of the Bedroom Furniture Discounts website is its unique “Free White Glove” delivery service which is available to customers in certain parts of the country.

To find out if they qualify for this service, customers simply need to enter their zip code into the correct field on the site, or during the checkout process. Below we’ve outlined our process so that you can achieve the same results with your future implementations.

How to check a zip code.

The Magento checkout process has methods for determining shipping options before a user even gets to the checkout page where they are able to “Get a Quote”.

In making use of this, we first created a “whiteglove” shipping method, which is similar to Magento’s built-in table rates method. You could also use “tablerates” for the same purpose. To recreate this you’ll need a controller, which looks something like this:

public function indexAction()
// Get the submitted zipcode.
$zipcode = (string) $this->getRequest()->get(‘zipcode’);

// Update the cart’s quote.
$cart = Mage::getSingleton(‘checkout/cart’);
$address = $cart->getQuote()->getShippingAddress();

// Find if our shipping has been included.
$rates = $address->collectShippingRates()
$qualifies = false;
foreach ($rates as $carrier) {
foreach ($carrier as $rate) {
if ($rate->getMethod() === ‘whiteglove’) {
$qualifies = true;

// Redirect user to either a success or failure page.
$this->_redirect( $qualifies ? ‘success_page’ : ‘failure_page’ );

Believe it or not, most of the work is now done! Here is a brief explanation of what just happened.

The zipcode is retrieved and passed as an URL parameter from a normal text field in a normal form. You can see that for yourself on several pages of Bedroom Furniture Discounts.
The cart has a quote and the quote has some addresses. We request the first shipping address, then request the rates that are applicable to it. Note that a country is needed but only the United States uses “zip” codes so the country code is fixed. Also note that Magento is built for an international audience and therefore calls the field by it’s more generic moniker, “postcode”.

We then loop through the collected rates and if our custom “whiteglove” is one of them then it’s a hit! A controller’s _redirect() function takes exactly the same parameters asgetUrl() so any URL can be generated.

Making it look nice.

To make our zipcode check popup in a new window the form is given atarget=”_blank” attribute. A small bit of javascript ensures that a window of the right size is used. In case that fails, or javascript is disabled by the customer, it falls back to submitting the form, and the target attribute causes a new window to be opened.

Additionally, we gave Bedroom Furniture Discounts two CMS pages for the “success” and “failure” scenarios. They maintain the content of these as they see fit.

Happily the shipping address is remembered as part of the quote when the cart was saved. When the customer visits the cart page (if products are already in the cart) they will see the quote form already filled out and the available shipping methods offered for them. When they move on to the checkout page the quote details are carried over there too and the shipping address has the zipcode filled again. This was quite unintentional but warmly received when it happened.