I develop observer method in Magento for filter payment methods based on shipping methods. This is my method:
class Devpassion_Paymentfilter_Model_Observer {
public function paymentMethodIsActive(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$carriers = Mage::getSingleton('shipping/config')->getActiveCarriers();
foreach ($carriers as $carrier) {
// $carrierCode = $carrier->getId();
if ($carrier->getId() == 'flatrate' ){
if($method->getCode() == 'checkmo' OR $method->getCode() == 'paypal_standard'){
$result->isAvailable = true;
}else{
$result->isAvailable = false;
}
}
}
}
}
Results of this is that for all shipping method this filter is true. So for all shipping method paypal and money check shows up and all other not.
Please advice me how to set up this condition to filter just for one specific shipping method.
$result->setData('is_available',false)
instead of setting that direct variable, since I think it's a varien object. The variable might also just beavailable
inside the object, with isAvailable() as the custom accessor.