cancel
Showing results for 
Search instead for 
Did you mean: 

What's wrong in my custom module?

What's wrong in my custom module?

magento CE 1.9

 

I'm trying to create a custom module in order to disable paypal payment method based on what shipping methos is selected. So I started off with this simple code that does not disable paypal, it should write some debug info to a log file - I'm trying to first get this script working before I move to more advanced stuff like disable payment method...

 

With this module no log file is created and the user is not sent to order confirmation page on checkout, so something is wrong

 

config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Audun_DisablePayPal>
      <version>0.0.1</version>
    </Audun_DisablePayPal>
  </modules>
  <global>
  	
    <models>
      <audun_disablepaypal>
        <class>Audun_DisablePayPal_Model</class>
      </audun_disablepaypal>
    </models>
      	
    <events>
      <checkout_controller_onepage_save_shipping_method>
        <observers>
          <audun_disablepaypal>
            <class>audun_disablepaypal/observer</class>
            <method>log_Method</method>
            <type>singleton</type>
          </audun_disablepaypal>
        </observers>
      </checkout_controller_onepage_save_shipping_method>
    </events>
  </global>
</config>

Audun_DisablePayPal.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Audun_DisablePayPal>
      <active>true</active>
      <codePool>local</codePool>
    </Audun_DisablePayPal>
  </modules>
</config>

Observer.php

<?php
/* Our class name should follow the directory structure of our Observer.php model, starting from the namespace, replacing directory separators with underscores. The directory of ousr Observer.php is following:
 app/code/local/Mage/ProductLogUpdate/Model/Observer.php */
class Audun_DisablePayPal_Model_Observer
{
  // Magento passes a Varien_Event_Observer object as the first parameter of dispatched events.
  public function log_Method(Varien_Event_Observer $observer)
  {
		$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
    Mage::log("{$shippingMethod} updated", null, 'audun_disablepaypal.log');
  }
}
?>

I guess it is a typo error, but I get blind to my own errors, can you see what I do wrong?

5 REPLIES 5

Re: What's wrong in my custom module?

I'm confused as to the purpose of this, but I'll tell you right off the bat, I do not see where you are obtaining the data from  for $quote.

 

Use the $observer variable to obtain the data sent by the dispatch.

 

If you are unaware of what was sent,

 

public function log_Method(Varien_Event_Observer $observer) {
...
}
 

simply,

//Stick this in there...

Zend_Debug::dump($observer);

For what you appear to be referencing, it might be

 

$quote = $observer->getEvent()->getQuote();

// DON'T Forget the return statement:

return $this;

// Also, do not have the PHP file end with a closing "?>" php tag. Remove that.

Re: What's wrong in my custom module?

here is my updated Observer.php, Checkout stops at selecting shipping method. I can select shipping methid, but when I click on "next" I'm not sent to the next step in checkout processs, it stays on shipping step... The good news is that it now logs, it put things into the log file

 

<?php
/* Our class name should follow the directory structure of our Observer.php model, starting from the namespace, replacing directory separators with underscores. The directory of ousr Observer.php is following:
 app/code/local/Mage/ProductLogUpdate/Model/Observer.php */
class Audun_DisablePayPal_Model_Observer
{
  // Magento passes a Varien_Event_Observer object as the first parameter of dispatched events.
  public function log_Method(Varien_Event_Observer $observer)
  {
  	Zend_Debug::dump($observer);
  	$quote = $observer->getEvent()->getQuote();
		$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
    Mage::log("{$shippingMethod} updated", null, 'audun_disablepaypal.log');
    return $this;
  }
}

not sure why or what stops it

Re: What's wrong in my custom module?

Anyone having a clue why my script don't let me go to next step after selecting shipping method. I select shipping method and click "next", but I'm sent back to "select shipping method" step. I assume the error is in the script above, maybe it return the wrong value or something. please help me

Re: What's wrong in my custom module?

This is causing the error:
Call to a member function getShippingAddress() on null in /home/nissehty/public_html/app/code/local/Audun/DisablePayPal/Model/Observer.php on line 9

 

anyone seeing what I do wrong? As far as I know the error is caused by $quote is null???

Re: What's wrong in my custom module?

Hi

 

I was thinking... maybe I do this completly wrong as my goal is to hide payment method based on what shipping method is selected

 

My code listen to the checkout_controller_onepage_save_shipping_method, but wouldn't it be better to listen for an event that is fired right before the payment mehods is shown? I'm thinking of this event for example: sales_order_payment_place_start

 

any ideas?