Question

How to make magento module for Cash on delivery payment method should visible only for some zip codes/pin codes and it can be check in product page also.

Was it helpful?

Solution 2

I have add this code here app/code/community/MSP/CashOnDelivery/Model/Cashondelivery.php in my costume COD and it works fine.

 public function isAvailable($quote = null)
   {
    if ($quote) {
        // Here is the list of restricted Zip Codes
        $restrictedZips = array('201301',
                                '201303',
                                '203207',
                                '203155',
                                '201308',
                                '203202',
                                '203207',
                                '203203');

        $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
        $customerZip = $address->getPostcode();

        if (!in_array($customerZip, $restrictedZips)) {
            return false;
        }
    }

return parent::isAvailable($quote);
} 

OTHER TIPS

add observer and doing code in

config.xml file like bwlok

<events>
            <payment_method_is_active>
                <observers>
                    <codcheck_payment_is_actve>
                        <type>singleton</type>
                        <class>codcheck/observer</class>
                        <method>paymentMethodIsActive</method>
                    </codcheck_payment_is_actve>
                </observers>
            </payment_method_is_active>
        </events>

and right require code in observer file

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top