I have asked this question on Magento Stackexchange without any success, hence me now asking here.
I'm using Magento Community Edition 1.9.0.1 and have correctly created and registered my module, but I can't seem to detect the shipping methods. Basically, I want to hide Cash on Delivery if Flat Rate or Free Shipping is chosen. Here is the code I have for my observer class:
class Kol_PaymentToggle_Model_Observer
{
public function paymentMethodIsActive(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$quote = $observer->getEvent()->getQuote();
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if($shippingMethod == "standardshipping" || $shippingMethod == "free") {
if($method->getCode() == 'cashondelivery' ) {
$result->isAvailable = false;
}
}
}
}
I'm guessing that I haven't used the correct shipping method code names or payment method code names, but I'm unsure. Anyone has any advice?
EDIT: I only have 3 shipping methods enabled:
- Collect In Store
Title = Collect in Store
Method Name = Collect In Store (Extension link) - Flat Rate
Title = Standard Delivery
Method Name = Standard Shipping - Free Shipping
Title = Free Delivery
Method Name = Free
EDIT 2: Output of config.xml
<?xml version="1.0"?>
<config>
<modules>
<Kol_PaymentToggle>
<version>0.0.1</version>
</Kol_PaymentToggle>
</modules>
<frontend>
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>Kol_PaymentToggle_Model_Observer</class>
<method>paymentMethodIsActive</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
Hopefully this extra information can prove useful towards helping me!
payment_method_is_active
, and the observer is calledpaymentfilter_payment_method_is_active
– maGzconfig.xml
output – maGz