2

we restricted only some zip codes for default COD payment method by adding below code in cashondelivery.php :

app/code/local/Mage/Payment/Model/Method/Cashondelivery.php

public function isAvailable($quote = null)
{
if ($quote) {

// Here is the list of restricted Zip Codes
$restrictedZips = array(
'641004'
,'641006'
);

$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$customerZip = $address->getPostcode();
if (!in_array($customerZip, $restrictedZips)) {
return false;
}
}

return parent::isAvailable($quote);
}

Now we are using custom COD & we are using following code :

public function isAvailable($quote = null)
    {
        if($quote && $quote->getBaseGrandTotal()<Mage::getStoreConfig('payment/mpcashondelivery/max_order_total') && $quote->getBaseGrandTotal()>Mage::getStoreConfig('payment/mpcashondelivery/max_order_total')) {
            return false;
        }
        $specificcountry = explode(",",Mage::getStoreConfig('payment/mpcashondelivery/specificcountry'));
        if(Mage::getStoreConfig('payment/mpcashondelivery/allowspecific')!=0 ){
            if(!in_array($quote->getBillingAddress()->getCountry(),$specificcountry)){
                return false;
            }
        }
        $cod_charges = Mage::getModel('mpcashondelivery/pricerules')->getAppliedPriceRules();
        if($cod_charges['error']){            
            return false;
        }
        return parent::isAvailable($quote);
    }

How to restrict only some zip codes for this custom COD ?

2

add code like below will work for you

if($quote && $quote->getBaseGrandTotal()<Mage::getStoreConfig('payment/mpcashondelivery/max_order_total') && $quote->getBaseGrandTotal()>Mage::getStoreConfig('payment/mpcashondelivery/max_order_total')) {
            return false;
        }
        $specificcountry = explode(",",Mage::getStoreConfig('payment/mpcashondelivery/specificcountry'));
        if(Mage::getStoreConfig('payment/mpcashondelivery/allowspecific')!=0 ){
            if(!in_array($quote->getBillingAddress()->getCountry(),$specificcountry)){
                return false;
            }
        }
         $cod_charges = Mage::getModel('mpcashondelivery/pricerules')->getAppliedPriceRules();
        if($cod_charges['error']){            
            return false;
        }
       $restrictedZips = array(
           '641004'
          ,'641006'
             );

         $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
          $customerZip = $address->getPostcode();
      if (!in_array($customerZip, $restrictedZips)) {
         return false;
       }
        }
  • working fine, Now it restricted for all zip codes, but i need to allow for zip codes i entered in above code, i tried with "641004", for this also its not showing COD. – user33510 Apr 1 '16 at 11:04
  • you want to show for restricted zipcode $restrictedZips = array( '641004' ,'641006' ); check this remove it from here then check – Qaisar Satti Apr 1 '16 at 11:05
  • Thansk for your support bro.... – user33510 Apr 1 '16 at 11:24
4

At magento,if you return value as false (return false;) from isAvailable() from a payment method class then that payment gateway becomes not available for current checkout.

So if you add your code at start of isAvailable(), then will works for you.

public function isAvailable($quote = null)
    {
    if($quote){
        $restrictedZips = array(
        '641004'
        ,'641006'
        );

    $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
    $customerZip = $address->getPostcode();
        if (!in_array($customerZip, $restrictedZips)) {
            return false;
            }
        }
        /* add rest of code  */
        *****       
    }
  • Thansk a lot, i just got an answer..... – user33510 Apr 1 '16 at 11:10
  • i checked this one, its working fine. – user33510 Apr 1 '16 at 11:16
  • you are awesome , after i got an answer also you are editing answer to help other users. – user33510 Apr 1 '16 at 11:25
  • At observer function change $event to $observer – Amit Bera Apr 1 '16 at 20:34
  • thanks for helping me here, please look at my other questions – user33510 Apr 3 '16 at 19:39

Your Answer

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