2

When one of us admins on our team creates a comment on an order, I'd like to show their name right their with the comment they wrote.

This will help us know who's commenting when we see a comment has been made.

I found somewhat of a solution for this for 1.4, but we're using 1.7, and I feel using the 1.4 solution would fail us here.

If anyone could help, that would be much appreciated. Thanks all!

SOLVED:

I listened to the answer by R.S, in his earlier, shorter edit, which said to simply add this code to:

/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);

And this works perfectly!

Community
  • 1
  • 1
stephen wise
  • 365
  • 4
  • 11
  • the solutions seems legit for 1.7 ... the approach is to add the user that created the comment to order_status_history collection (`sales_flat_order_status_history` table) – FlorinelChis Oct 23 '12 at 18:39

1 Answers1

1

If you want to make it easier you could append the username of who write the comment to before or after the comment, instead of creating new fields in the database and less code. (eg. "This is my comment - added by xxxx yyyyy)

By creating a custom module that extend admin order controller. (see 'Overriding Frontend Core Controllers' http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/)

Create /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>

Create /app/code/local/RWS/OrderComment/controllers/Adminhtml/Sales/OrderController.php

(copy addCommentAction method from /app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php)

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

Create 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>
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • R.S, this works perfectly! Thank you for this simple, yet flawless solution. The 1.4 "fix" was just too complicated, and was taking me forever to get right. Thanks! – stephen wise Oct 24 '12 at 13:20