2

当我们团队中的一位管理员对订单发表评论时,我想在他们写的评论中显示他们的名字。

这将帮助我们在看到评论时知道谁在评论。

为 1.4 找到了一些解决方案但我们正在使用 1.7,我觉得使用 1.4 解决方案会让我们失败。

如果有人可以提供帮助,那将不胜感激。谢谢大家!

已解决

我听了 RS 的回答,在他较早的较短的编辑中,它说只需将此代码添加到:

/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php

    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'] . " Add by {$user['firstname']}", $data['status'])
                ->setIsVisibleOnFront($visible)
                ->setIsCustomerNotified($notify);

这非常有效!

4

1 回答 1

1

如果你想让它更容易,你可以在评论之前或之后附加写评论的用户名,而不是在数据库中创建新字段和更少的代码。(例如。“这是我的评论 - 由 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>
于 2012-10-23T21:48:02.830 回答