4

I have a module which listens to a few events. It works fine in at least a dozen installations I have tested it on.

On on specific installation, a client which I installed it, on Magento version 1.4.1.1, It does not work. When I tested his system, and I fire the events manually, eg Mage::dispatchEvent('..') the observer does listen to them.

What should I look into ? I do not have a clue what could be the reason for this.

Jonathan Day
  • 18,519
  • 10
  • 84
  • 137
user145100
  • 173
  • 2
  • 8
  • Can you give an example of an event that it appears to miss out on for reference? – Joe Mastey Oct 13 '10 at 15:05
  • for example the event checkout_cart_product_add_after – user145100 Oct 13 '10 at 18:01
  • I've written a tutorial with working code, which is located [here][1]. It's written for v1.7 but I see no reason why it would not be backwards compatible other than the fact that the XML file structure is more involved. [1]:http://z900collector.wordpress.com/magento/magento-events/ – z900collector Dec 04 '12 at 00:41

2 Answers2

19

There's a few reasons this could be happening

  1. The event you're trying to listen for doesn't exist in your version of Magento

  2. Someone's hacked the core file and accidentally removed the event you're listening for

  3. Someone's overridden a method

  4. Your observer is setup incorrectly, and Magento doesn't "see" it.

  5. Your observer is setup correctly, but the old configuration is cached

The steps I'd take to debug this are

  1. Make sure the merged global config has your event configuration. If it doesn't clear out your caches until it shows up

  2. Download a fresh version of the source code and diff your app/code/core/ and lib/ against the virgin version. Type man diff from a unix prompt yo learn about the diff tool if you're not already familiar with it.

  3. Grep (or ack) the core codebase for the event you're trying to listen for.

  4. Temporarily add logging code to Mage::dispatchEvent in app/Mage.php to ensure the event you're looking for is really firing.

  5. Starting with Mage::dispatchEvent, follow the execution path to the point where listeners are invoked and see why the code in Magento isn't calling your method

The first time you do this will be a time sink, so make notes along the way about where thinks happen in the core Magento system code. That way, the next time you debug a similar issue it'll go that much quicker (if you really wanted to be nice, you could share what you find here, on your blog, or in the Magento wiki)

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • The cause cannot be 1 or 2 since a manual dispatch did nothing. – clockworkgeek Oct 13 '10 at 22:09
  • Thanks for the answer Alan. Big fan of yours. I do not have full access to the magento source since its at a remote client. I can however change files on my module's directory (limited access). I did suspect of reason number 2 or 3. a cache refresh is a wise option. I didn't think of that. will post updates later on. – user145100 Oct 13 '10 at 22:18
  • @clockworkgeek it can be 1 or 2, it did dispatch manually, it cant be 2 & 3 because it fired manually – Himberjack Oct 14 '10 at 08:34
  • Some of this are almost certainly not the case here, but this is my standard set of "an event listener isn't working" debugging tips. – Alana Storm Oct 14 '10 at 21:51
  • 3
    Another thing to look for is whether your tag in config.xml is inside the tag or the tag. That detail can ruin your whole day :) – Tyler V. Jun 17 '14 at 00:26
  • rm -rf var/cache/* did the trick, thanks for the 5th item of yor checklist ;) – nicolallias Sep 15 '16 at 07:53
0

As I recently discovered, a module can show as enabled in Magento but actually not work if the folder name for the module begins with a lowercase letter. Perhaps this will allow someone else to retain their hair in the future.

Clonkex
  • 3,373
  • 7
  • 38
  • 55