我有一个产品注册扩展,它在注册保存后调度一个事件.如果虚拟产品与注册产品相关,另一个扩展程序使用该事件为虚拟产品生成优惠券.
I have an extension for product registration that dispatches an event after the registration is saved. Another extension uses that event to generate a coupon for a virtual product if it is related to the registered product.
我需要取回有关生成的优惠券的数据,以便通过电子邮件将其连同产品注册的详细信息一起发送给用户.
I need to get back data on the generated coupon to send to the user in an email along with the details of their product registration.
有没有办法将数据从观察者返回到事件被调度的地方?
Is there a way to return data from the observer back to where the event is dispatched?
Magento 中有一个技巧可用于您的目的.由于您可以将事件数据(如产品或类别模型)传递给观察者,因此还可以创建一个容器,从中获取这些数据.
There is a trick available in Magento for your purpose. Since you can pass event data to the observers, like product or category model, it also possible to create a container from which you can get this data.
例如,可以在调度程序中执行此类操作:
For instance such actions can be performed in dispatcher:
$couponContainer = new Varien_Object();
Mage::dispatchEvent('event_name', array('coupon_container' => $couponContainer));
if ($couponContainer->getCode()) {
// If some data was set by observer...
}
观察者方法如下所示:
public function observerName(Varien_Event_Observer $observer)
{
$couponContainer = $observer->getEvent()->getCouponContainer();
$couponContainer->setCode('some_coupon_code');
}
享受并玩得开心!
这篇关于将数据从 Magento 中的事件观察器返回给调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 SELECT(MYSQL/PHP) 中加入 2 个表Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 个表)
如何使<option selected=“selected">由How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 设置?)
使用 PHP 中的数组自动填充选择框Auto populate a select box using an array in PHP(使用 PHP 中的数组自动填充选择框)
PHP SQL SELECT where like search item with multiple wordsPHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 从 MSSQL-SELECT 产生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(),名称 ASCMySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名称 ASC)