Question

I've made my admin configuration for cash on delivery payment as applicable only to specific country i.e, USA

Below my cases in checkout page,

Billing Country => USA, Shipping Country => USA | COD Available
Billing Country => USA, Shipping Country => OTHER | COD Available
Billing Country => OTHER, Shipping Country => USA | COD Not Available
Billing Country => OTHER, Shipping Country => OTHER | COD Not Available

So this clearly shows that COD configuration of applicable country is pointing only to billing address.

Any way to make this condition to check shipping country instead of billing country ?

Was it helpful?

Solution 2

I've figured it out,

Event in config.xml,

            <payment_method_is_active>
                <observers>
                    <disable_cod_non_indian_shipping>
                        <class>Caritor_Mobileapp_Model_Observer</class>
                        <method>disableCOD</method>
                    </disable_cod_non_indian_shipping>
                </observers>
            </payment_method_is_active>

My Observer.php

public function disableCOD($observer){
        $result=$observer->getEvent()->getResult();
        $MethodInstance=$observer->getEvent()->getMethodInstance();
        $quote=$observer->getEvent()->getQuote();
        if($quote && $quote->getId()):
            $ShippingAddress=$quote->getShippingAddress();
            $country_id = $ShippingAddress->getCountryId();
            if($MethodInstance->getCode()=='cashondelivery'){
                if($country_id == 'US'){                
                    $result->isAvailable = true;
                } else {
                    $result->isAvailable = false;
                }
            }
        endif;
    }

Above code makes cashondelivery payment visible only if shipping country is set to United States.

Note: This maked cash on delivery payment available even it's disabled from magento admin.

OTHER TIPS

You would have to make a extension that observes payment_method_is_active event and decide if your method is active or not

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