dongnuoyi8833 2012-11-07 19:52
浏览 48
已采纳

将数据从Magento的事件观察者返回给调度员

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?

  • 写回答

2条回答 默认 最新

  • dowe98261 2012-11-07 20:18
    关注

    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...
    }
    

    And an observer method can look like the following:

    public function observerName(Varien_Event_Observer $observer) 
    {
        $couponContainer = $observer->getEvent()->getCouponContainer();
        $couponContainer->setCode('some_coupon_code');
    }
    

    Enjoy and have fun!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C