0

we are using customized shipping method something like "flat rate" shipping method.

we have to restrict the customer from buying products from some zip codes.

how we can achieve this?

  • do you mean you want to disable flat rate shipping method for some zipcodes ? – Akhilesh Patel Oct 5 '15 at 7:15
  • no, i integrated one more shipping method as similar to "flat rate". we are using only that shipping method in our site. if we use table rate shipping methiod , we can restrict "zip codes" but we are using customized shipping method as like "flat rate", i have to restrict the zip codes for that shipping method – Baby in Magento Oct 5 '15 at 7:17
1

In your shipping method carrier module you should have the method collectRates.

You can make it look like this:

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    $postCode = $request->setDestPostcode();
    $restrictedCodes = array(....); //restricted values. they can come from anywhere
    if (in_array($postCode, $restrictedCodes)) { 
         return false;
    }
    //rest of your method here
}
  • i will try @Marius...... – Baby in Magento Sep 28 '15 at 14:24
  • sorry for delay, there was no internet, is this right = > pastebin.com/gPXwRMn1 because i gave "1" in restricted codes, now its not supporting any zip codes – Baby in Magento Sep 28 '15 at 15:12
  • if i give = > array(1, 2) = > than its not allowing for any zip codes. if i give = > array(11, 22) = > than its allowing for all zip codes. means if i give single digit means its not allowing for all zip codes, but if i give more than single digit, than its allowing for all zip.... – Baby in Magento Sep 29 '15 at 5:32
  • 1
    Theoretically this should not happen. Try to debug the line and see the value of $postCode – Marius Sep 29 '15 at 5:42
  • i am really not getting what to do..... – Baby in Magento Sep 29 '15 at 5:50
1

You can try my recently created extension

app\etc\modules\Sipping_Disable.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Sipping_Disable>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Sipping_Disable>
  </modules>
</config>

app\code\local\Sipping\Disable\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Sipping_Disable>
      <version>0.1.0</version>
    </Sipping_Disable>
  </modules>
  <global>
    <models>
      <disable>
        <class>Sipping_Disable_Model</class>
        <resourceModel>disable_mysql4</resourceModel>
      </disable>
            <shipping>
                <rewrite>
                    <shipping>Sipping_Disable_Model_Shipping_Shipping</shipping>
                </rewrite>
            </shipping>
    </models>
  </global>
</config> 

app\code\local\Sipping\Disable\Model\Shipping\Shipping.php

<?php
class Sipping_Disable_Model_Shipping_Shipping extends Mage_Shipping_Model_Shipping
{
    public function collectCarrierRates($carrierCode, $request)
    {
        if (!$this->_isAvailable($carrierCode, $request)) {
           return $this;
        }
        return parent::collectCarrierRates($carrierCode, $request);
    }

    /**
     * @param string $carrierCode
     * @param Varien_Object $request
     * @return bool
     */
    protected function _isAvailable($carrierCode, $request)
    {
          $regionCode = $request->getDestRegionCode();
            $cart = Mage::getSingleton('checkout/session')->getQuote();
            $ZipCodes = array('12345','54454'); //all zip codes put here where you want disable shipping
            $shippingAddress = $cart->getShippingAddress();
            $zip = $shippingAddress->getPostcode();
           switch ($carrierCode) {
                case 'youshippingCode': // put your shipping code
                if (in_array($zip ,$ZipCodes)) {
                    return false;
                }
                break;

      }
        return true;
    }
}
  • sure, i will try this ..... can you give me an option for all zip codes to put where we can enable shipping – Baby in Magento Sep 28 '15 at 5:47
  • 1
    you want to manage disable zip's code from admin ? – Arunendra Sep 28 '15 at 5:49
  • 1
    where you want to disable shipping – Arunendra Sep 28 '15 at 5:52
  • 1
    Please put those zipcodes in $ZipCodes = array('12345','54454'); where you want to restrict the customer from buying products – Arunendra Sep 28 '15 at 5:55
  • 1
    Make sure that you have to put right shipping code here :case 'youshippingCode': // put your shipping code – Arunendra Sep 28 '15 at 6:59

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.