How to disable specfic payment method for specfic products in Magento

How to disable specfic payment method for specfic products If you want to disable a specfic payment method for specfic products then follow these steps. 1.Make a new file in app/etc/module/Arunendra_Disablepayment.xml copy and Paste below code in that file

<?xml version="1.0"?>



     
        true
        local

    


2.Now make module folder inside app/code/local/Arunendra/Disablepayment 3.Make new folder and file inside app/code/local/Arunendra/Disablepayment/etc/config.xml and copy and paste below code in that file.


<?xml version="1.0"?>

    

        
            1.0.1

        
    
    
        
            
            Arunendra_Disablepayment_Model
            
        
    
    
        
            
                
                    
                        singleton
                        disablepayment/observer
                        filterpaymentmethod
                    
                
            
        
    

4.Make new folder and file inside app/code/local/Arunendra/Disablepayment/Model/Observer.php and copy and paste below code in that file.
<?php
class Arunendra_Disablepayment_Model_Observer {
 public function filterpaymentmethod(Varien_Event_Observer $observer) {
            /* call get payment method */
        $method = $observer->getEvent()->getMethodInstance();
        if($method->getCode()=='paypal_express'){
         $productWeight  = array(); 
   $CartSession = Mage::getSingleton('checkout/session');
   foreach($CartSession->getQuote()->getAllItems() as $item)
   {
    $product_id = $item->getProductId();
    $obj = Mage::getModel('catalog/product')->load($product_id);
    $productWeight[] = $obj->getDisablepayment();
   }
        if(!in_array(1,$productWeight)){
            $result = $observer->getEvent()->getResult();   
            $result->isAvailable = true;
            return;
            }
            else{
            $result = $observer->getEvent()->getResult();   
            $result->isAvailable = false;
            }

        }
        return;
    }
}
5. Login to your admin section.
6. create a attribute,make sure attribute code must be (disablepayment) and type must be yes/no.
7.Assign this attribute in attribute set.

You can download module here.

Now clear chache it finished.!

No comments:

Post a Comment