事件不触发/或观察者不在 magento 中工作 [英] Events not firing/or observer not working in magento

查看:20
本文介绍了事件不触发/或观察者不在 magento 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块可以监听一些事件.它至少在我测试过的十几种安装中都运行良好.

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

在特定安装上,我安装了它的客户端,在 Magento 版本 1.4.1.1 上,它不起作用.当我测试他的系统并手动触发事件时,例如 Mage::dispatchEvent('..') 观察者确实会监听它们.

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.

推荐答案

发生这种情况的原因有几个

There's a few reasons this could be happening

  1. 您尝试侦听的事件在您的 Magento 版本中不存在

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

有人入侵了核心文件并意外删除了您正在侦听的事件

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

有人重写了一个方法

您的观察者设置不正确,Magento 没有看到"它.

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

您的观察者设置正确,但旧配置被缓存

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

我要调试的步骤是

  1. 确保合并的全局配置具有您的事件配置.如果在它出现之前它没有清除你的缓存

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

下载源代码的新版本,并将您的 app/code/core/lib/ 与原始版本进行比较.如果您还不熟悉 diff 工具,请在 unix 提示符下键入 man diff.

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.

Grep(或ack)您尝试监听的事件的核心代码库.

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

临时将日志代码添加到 app/Mage.php 中的 Mage::dispatchEvent 以确保您正在寻找的事件真正触发.

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

Mage::dispatchEvent 开始,沿着执行路径到监听器被调用的地方,看看为什么 Magento 中的代码没有调用你的方法

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

您第一次这样做会很费时间,因此请在此过程中记下 Magento 核心系统代码中发生的想法.这样,下次您调试类似问题时,它会变得更快(如果您真的想保持友好,可以在这里、博客或 Magento wiki 中分享您找到的内容)

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)

这篇关于事件不触发/或观察者不在 magento 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆