1

How to make a product available only in specific cities. Example organic products will be available only in certain cities, so during checkout if the user selects city other than specified then the checkout process should give error stating "Products available only in so and so city.". Checkout process should not be completed unless a proper city is selected. I have tried with Shopping cart price rules but no luck. Any ideas or suggestions please?

Thanks,

  • You mean product A is available only for X, Y, Z ... and product B is for X, T, W ... cities. Or shipping only X, Y, ... cities? – mageUz Jun 3 '13 at 14:56
  • I mean product A is available only for X,Y,Z and product B is available for T,W,Z cities. Any idea how to do it? – asifa Jun 3 '13 at 15:16
1

Create a product attribute called city that has a plaintext City Name - match on this in an observer for the predispatch event of the Mage_Checkout_OnepageController::saveShippingAction.

class MyCompany_MyModule_Model_Observer {

    public function saveShippingActionPredispatch($observer){

        $billing = $observer->getEvent()->getController()->getRequest()->getPost('billing');

        foreach(Mage::getSingleton('checkout/session')->getQuote()->getAllItems() as $item){
            if(!$billing['city']==$item->getProduct()->getCity()){
                Mage::throwException("You can't buy this product because you're shipping to the wrong place!");
            }
        }
    }

}

However, this is the easiest part - the reason Zones Manager is so complex is because this is a very complex problem. Thinking through this - there are many considerations:

  • How to handle misspelled city names? (probably would use Zip/Postcodes, obviously)
  • How to obtain /manage a list of postcodes?
  • How to query the customer for their ultimate shipping address before displaying products to them? Geolocation?
  • How to limit the catalog to only show regional items?
  • If you instead use category structure for products / cities, how do you limit them from purchasing a product that wasn't intended for a city at the end of the day?
  • Are you concerned about this complexity impacting your conversion rate?

(corrected the code by putting the missing curly bracket to close the foreach loop)

0

In Zones Manager extension you could make a product available in specific zones which, besides countries and states/ provinces, may also be comprised of zip/postal codes or zip/postal code ranges: http://www.magentocommerce.com/magento-connect/catalog/product/view/id/17079/

  • It is commercial and very complicated. Do you know anything free and easy to use method? Thanks – asifa Jun 6 '13 at 7:57

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.