在magento中向订单添加评论 [英] Adding a comment to order in magento

查看:57
本文介绍了在magento中向订单添加评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究magento.我想添加一项功能,当用户下订单时,会将注释添加到订单的历史注释中.我遍历了代码,才知道该函数

I am working on magento. I want add a functionality that when user places the order, a comment is added to the history comment of the order. I have gone through the code and come to know that the function

 public function addStatusHistoryComment($comment, $status = false)

in order.php用于添加注释.我想在用户下订单时访问它.那我该怎么办呢?有人知道吗?

in order.php is used to add the comment. I want to access it when user places the order. So how can i do that? Do anyone have any idea?

推荐答案

与Magento中的所有内容一样,

首先,您需要编写一个模块.在该模块中,您可以侦听checkout成功事件-checkout_onepage_controller_success_action.使用etc/config.xml模块来执行此操作,例如:

First you need to write a module. In that module you could listen for checkout success event - checkout_onepage_controller_success_action. Do that with the module etc/config.xml, e.g:

    <events>
        <checkout_onepage_controller_success_action>
            <observers>
                <whatever>
                    <type>singleton</type>
                    <class>whatever/observer</class>
                    <method>checkout_onepage_controller_success_action</method>
                </whatever>
            </observers>
        </checkout_onepage_controller_success_action>
    </events>

在观察者中加载最后一个订单,在其上添加注释,然后保存订单.您描述的方法将完美地工作.您还可以使用订单状态进行操作,这样可以使您在需要的情况下通过电子邮件向客户发送电子邮件:

In your observer you load the last order, append your comment to it and then you save your order. The method you describe will work perfectly. You can also do things with the order status, doing so enables you to email the customer if need be:

public function checkout_onepage_controller_success_action($observer) {
    $orderIds=$observer->getData('order_ids');
    foreach ($orderIds as $orderId) {
        $order = new Mage_Sales_Model_Order();
        $order->load($orderId);

        ... Do Something!

        $order->setState('processing', 'invoiced', 'Hello World!');
        $order->save();
    }

希望对您有帮助!

这篇关于在magento中向订单添加评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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