如果你想让它更容易,你可以在评论之前或之后附加写评论的用户名,而不是在数据库中创建新字段和更少的代码。(例如。“这是我的评论 - 由 xxxx yyyyy 添加)
通过创建扩展管理订单控制器的自定义模块。(请参阅“覆盖前端核心控制器” http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/)
创建 /app/code/local/RWS/OrderComment/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<RWS_OrderComment>
<version>0.1.0</version>
</RWS_OrderComment>
</modules>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<RWS_OrderComment before="Mage_Adminhtml">RWS_OrderComment_Adminhtml</RWS_OrderComment>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
创建 /app/code/local/RWS/OrderComment/controllers/Adminhtml/Sales/OrderController.php
(从 /app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php 复制 addCommentAction 方法)
<?php
include_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'OrderController.php';
class RWS_OrderComment_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
public function addCommentAction(){
......
// get the login info of current user
$_user = Mage::getSingleton('admin/session');
$user['email'] = $_user->getUser()->getEmail();
$user['firstname'] = $_user->getUser()->getFirstname();
$user['lastname'] = $_user->getUser()->getLastname();
$order->addStatusHistoryComment($data['comment'] . " Added by {$user['firstname']}", $data['status'])
->setIsVisibleOnFront($visible)
->setIsCustomerNotified($notify);
}
}
创建 app/etc/modules/RWS_OrderComment.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<RWS_OrderComment>
<active>true</active>
<codePool>local</codePool>
</RWS_OrderComment>
</modules>
</config>