简体   繁体   English

添加评论以在magento中订购

[英]Adding a comment to order in magento

I am working on magento. 我正在研究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 is used to add the comment. 在order.php中用于添加注释。 I want to access it when user places the order. 我想在用户下订单时访问它。 So how can i do that? 那我该怎么做呢? Do anyone have any idea? 有人有任何想法吗?

As with anything in Magento there are many ways. 和Magento中的任何东西一样,有很多方法。

First you need to write a module. 首先,您需要编写一个模块。 In that module you could listen for checkout success event - checkout_onepage_controller_success_action. 在该模块中,您可以监听结账成功事件 - checkout_onepage_controller_success_action。 Do that with the module etc/config.xml, eg: 使用模块etc / config.xml执行此操作,例如:

    <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();
    }

I hope that helps! 我希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM