Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Payment mode hidden for shipping method
 
mcaoua
Jr. Member
 
Total Posts:  14
Joined:  2009-04-01
Switzerland
 

Hello,

Is it possible to make a payment mode (cash on delivery) disabled when customer choose one shipping method (DHL) ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LindyKyaw
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2008-01-02
Los Angeles
 

You can overwrite Mage_Payment_Block_Form_Container class _canUseMethod.

In your Mage_Custom_Block_Payment_Form, you can do as following

protected function _canUseMethod($method)
{
    $canuseMethod 
parent::_canUseMethod($method);
    
// we would like to check only method is availanle
    
if ($canuseMethod{
        $method
->getConfigData('min_order_total');
        
$pattern '/^dhl_(.)+/';
        if (
$method->->getCode()=='cash' &&
            
$preg_match($pattern,$this->getQuote()->getShippingAddress()->getShippingMethod())) {
            
//disable cash payment method for dhl shipping method
            
return false;            
        
}
    }
    
return $canuseMethod;
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
mcaoua
Jr. Member
 
Total Posts:  14
Joined:  2009-04-01
Switzerland
 

@LindyKyaw : thank a lot for your reply.

I found the function _canUseMethod in magento\app\code\core\Mage\Payment\Block\Form\Container.php

But I’m not sure to understand wich file I have to change, with your code, could you be more precise ?

I think I have to put my files in \magento\app\code\local\Mage\… to be sure that they will not be overwritten by the next release.

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top