我们如何使用opencart事件? [英] How can we use opencart events?

查看:257
本文介绍了我们如何使用opencart事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多有关opencart触发器的信息,但没有找到合适的示例.在opencart 2.0中,有一些触发器,开发人员可以在这些触发器上钩上功能并执行某些操作,例如wordpress动作和过滤器.例如在

I have searched a lot about opencart triggers but didn't find a proper example. In opencart 2.0 there are triggers on which developer can hook function and perform something just like wordpress action and filters i guess. For example in

catalog/model/checkout/order.php

有一个触发器$this->event->trigger('post.order.history.add', $order_id)

有人可以帮我把我的功能挂在上面的触发器上吗?

Can someone help me to hook my function on the above trigger?

推荐答案

重要说明:此答案适用于OC> 2.0.x.x和< 2.2.x.x.

Important Note: this answer applies to OC >2.0.x.x and <2.2.x.x.

这里的问题是使用(搜索)了一个错误的单词-您应该搜索的正确单词是 event ,并从中得出事件监听器触发事件(不幸的是,在尝试搜索事件监听器时都没有运气,并且仍然缺少2.0的文档).

The problem here is a wrong word being used (and searched for) - the right one you should be searching for is event, and from it derived event listener and trigger event (unfortunately, hadn't luck when trying to search for those either and the documentation for 2.0 is still missing).

现在,我相信整个背景更加容易理解,特别是如果您对其他框架的事件有一定的了解(也许是 jQuery ?),但是这里只是如何使用事件的快速指南(在OC 2.0中):

Now I believe the whole background is much more understandable, especially if you have some knowledge about events from other frameworks (maybe jQuery?) but here is just a quick guide how to work with events (in OC 2.0):

  • 首先,我们需要注册一个事件侦听器,如下所示:

  • first we need to register an event listener, like this:

$this->event->register('post.order.history.add', 'checkout/order/send_email');

在某些地方触发了事件,例如

on certain places an event is triggered, e.g.

$this->event->trigger('pre.order.history.add', $order_id);

$this->event->trigger('post.order.history.add', $order_id);

如果已注册事件(以其名称post.order.history.add标识)侦听器,则会在触发器上调用它

if the event (identified by it's name post.order.history.add) listener was registered it will be invoked on trigger

有关更多信息或自行解决,您可以查看system/engine/event.php(现在没有更多可使用的内容了.)

For more information or to figure it out on your own you may have a look into system/engine/event.php (there is nothing more to work with right now).

这篇关于我们如何使用opencart事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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