stephen wise
stephen wise

Reputation: 365

How to show user name of which user created a comment on an order in Magento 1.7

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!

Upvotes: 2

Views: 1603

Answers (1)

MagePal Extensions
MagePal Extensions

Reputation: 17656

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>

Upvotes: 1

Related Questions