How to disable Cash On Delivery on specific product type
You can do this by Magento Event/Observer
First,using payment_method_is_active
disable on depends current quote product type.
Code for this:
Module config.xml code:
<global>
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>yourmodel/observer</class>
<method>filterpaymentmethod</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
</global>
Observer code is:
<?php class YOURNANESPACE_YOURMODULE_Model_Observer { public function filterpaymentmethod(Varien_Event_Observer $observer) { /* call get payment method */ $method = $observer->getEvent()->getMethodInstance(); /* get Quote */ $quote = $observer->getEvent()->getQuote(); $result = $observer->getEvent()->getResult(); if (empty($quote) || (null === $quote)) { return $this; } /* Disable Your payment method for adminStore */ if ($method->getCode() == 'YOUR_PAYMENT_METHOD_CODE') { foreach ($quote->getAllItems() as $item) { // get Cart item product Type // if ($item->getProductType() == 'YourProductType'): $result->isAvailable = false; endif; } } } }
for that you need to use magento payment_method_is_active
event
I am assuming you know how to develop magento extension[If not then please check this answer you get whole module
Write this code in your config.xml
from app>code>codepool>namespace>package>etc
<global>
...
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>PaymentFilter_Model_Observer</class>
<method>paymentMethodIsActive</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
...
</global>
Create observer file app/code/codepool>namespace>package/Model/Observer.php
class namespace_package_Model_Observer {
public function paymentMethodIsActive(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
if($someTrueConditionGoesHere){
$result->isAvailable = true;
}else{
$result->isAvailable = false;
}
}
}