0

I'm trying to set an observer that fires on customer login and it doesn't appear to be set in magento (and therefore doesn't fire). I've debugged core files and the dispatchEvent function is being fired correctly, but my observer doesn't appear to exist in the registered events.

My code is as follows:

Foo\Bar\etc\config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Foo_Bar>
            <version>0.0.1</version>
        </Foo_Bar>
    </modules>
    <global>
        <models>
            <foo_bar>
                <class>Foo_Bar_Model</class>
            </foo_bar>
        </models>

... ... ...

        <events>
            <!-- fire on login -->
            <customer_login>
                <observers>
                    <foo_bar>
                        <class>foo_bar/observer</class>
                        <method>customerLogin</method>
                        <type>singleton</type>
                    </foo_bar>
                </observers>
            </customer_login>

... ... ...

        </events>
    </global>
</config>

Foo\Bar\Model\Observer.php

<?php
class Foo_Bar_Model_Observer extends Mage_Core_Model_Abstract
{
    public function customerLogin(Varien_Event_Observer $observer)
    {
        die('test'); // Doesn't do anything
    }

... ... ...

}

As I said before, I have about 6 other observers with basically identical configurations and methods that all work fine.

Can anyone help me out in pointing me to where I've gone wrong? Does the customer_login observer require some extra code to work correctly?

Thanks in advance!

  • Erease your cache and try again. – santiago glez May 19 '16 at 16:23
1
<customer_login>
  <observers>
      <foo_bar> <!-- foo_bar should be unique tag for within all customer_login observers-->
          <class>foo_bar/observer</class>
          <method>customerLogin</method>
          <type>singleton</type>
      </foo_bar>
  </observers>
</customer_login>

Observer

class Foo_Bar_Model_Observer
{
    public function customerLogin(Varien_Event_Observer $observer)
    {
        Mage::log('some message here'); // Doesn't do anything
    }
}

And also check if exception.log (admin->config->developer) and developer mode (index.php) is on.

  • Ahh, I'd not checked the logs properly and there was an error at the start my function that was preventing it from getting to where I'd had my die statement. Thanks for nudging me that way! – 9point6 Apr 11 '14 at 9:50
0

Important to know: customer_login - event won't be dispatched if customer login fails (f.e. in case password is wrong)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.