title: Magento - OnePage Checkout - Hide Payment method depending on Shipping Method
body: <p>I have asked this question on <a href="https://magento.stackexchange.com/questions/41075/onepage-checkout-hide-payment-method-depending-on-shipping-method">Magento Stackexchange</a> without any success, hence me now asking here.</p>
  
  <hr>
  
  <p>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 <strong>Cash on Delivery</strong> if <em>Flat Rate</em> or <em>Free Shipping</em> is chosen. Here is the code I have for my observer class:</p>
  
  <pre><code>class Kol_PaymentToggle_Model_Observer
  {
      public function paymentMethodIsActive(Varien_Event_Observer $observer) {
          $event  = $observer-&gt;getEvent();
          $method = $event-&gt;getMethodInstance();
          $result = $event-&gt;getResult(); 
          $quote = $observer-&gt;getEvent()-&gt;getQuote();
          $shippingMethod = $quote-&gt;getShippingAddress()-&gt;getShippingMethod();
          if($shippingMethod == "standardshipping" || $shippingMethod == "free") {
              if($method-&gt;getCode() == 'cashondelivery' ) {
                  $result-&gt;isAvailable = false;
              }
          }
      }
  }
  </code></pre>
  
  <p>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?</p>
  
  <p><strong>EDIT:</strong>
  I only have 3 shipping methods enabled:</p>
  
  <ul>
  <li><strong>Collect In Store</strong> <br />Title = Collect in Store <br />Method Name = Collect In Store (<a href="http://www.magentocommerce.com/magento-connect/collect-in-store-checkout-shipping-option.html" rel="nofollow noreferrer">Extension link</a>)</li>
  <li><strong>Flat Rate</strong> <br/>Title = Standard Delivery <br/>Method Name = Standard Shipping</li>
  <li><strong>Free Shipping</strong> <br/>Title = Free Delivery <br/>Method Name = Free</li>
  </ul>
  
  <p><strong>EDIT 2:</strong>
  Output of <em>config.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
      &lt;modules&gt;
          &lt;Kol_PaymentToggle&gt;
              &lt;version&gt;0.0.1&lt;/version&gt;
          &lt;/Kol_PaymentToggle&gt;
      &lt;/modules&gt;
      &lt;frontend&gt;
          &lt;events&gt;
              &lt;payment_method_is_active&gt;
                  &lt;observers&gt;
                      &lt;paymentfilter_payment_method_is_active&gt;
                          &lt;type&gt;singleton&lt;/type&gt;
                          &lt;class&gt;Kol_PaymentToggle_Model_Observer&lt;/class&gt;
                          &lt;method&gt;paymentMethodIsActive&lt;/method&gt;
                      &lt;/paymentfilter_payment_method_is_active&gt;
                  &lt;/observers&gt;
              &lt;/payment_method_is_active&gt;
          &lt;/events&gt;
      &lt;/frontend&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>Hopefully this extra information can prove useful towards helping me!</p>