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 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程