Add Username to Order Comment History

Is there a simple way to add the username of the person who is making the comment in the admin history to the comment thread on the order?

— edit —

Another way of asking this would be how do I add an additional field to the comment history model so that I can override the appropriate models and templates inserting that data into the data structure.

Magento add existing comment to order email

I have installed the iwd_onepagecheckout extension. Customers have the possibility to add a comment to their order. Now I want to add this ‘comment’ to the order email. The comment is to be saved in T



Add svn comment (revision history) to (script) file

Is it possible with Subversion to add the Revision History to a file with a svn property as with Id, Rev, Author? We would like to have the revision history automatically added to the beginning of a f

Adding a comment to order in magento

I am working on 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 func

PRAW: Comment Submitter’s Username

I’m developing a reddit bot that needs to know which user submitted a comment. According to the PRAW API wrapper docs, there’s no specific way to get the username of a Comment object’s author. Ideall

Facebook FQL comment username = anonymous user

When quering the FQL comment table like this: SELECT post_fbid, fromid, username, time, text FROM comment WHERE post_id = id I am getting the results but username for every comment is Anonymous User

Comment syntax history

In early Tcl versions, was the comment command (#anything) treated exactly as a normal command (parsed) with the only exception that the arguments weren’t sent anywhere? So you could do this… % # {

How we Add new comment field to admin order view page

i want to add some custom text area to add admin comment for orders that added by front end. and i want to save it to order table from ajax. i’m trying to create custom module but it wasn’t success.

Get youtube comment Username [closed]

I need help trying to get a YouTube comment Username to transferred from the web browser to a listbox. I am trying to do this without the YouTube API. I have been searching for a while now and got not

TFS 2010 History comment edit

Is there anyway to edit coments in the history section after saving the work item? Nick

MySQL Reporting – Order History

I have to create a MySQL Query for a report. I have a table history which keeps record of status changes of a product’s order. I have these statuses for an order’s life cycle (the flow of an order):

Answers

If you want to add the username who is currently logged in and making change in order or commenting on order. you need to add an attribute to magento.

Create a Module say Audit app / etc / modules / Namespace_Audit.xml

<modules>
    <Namespace_Audit>
        <active>true</active>
        <codePool>local</codePool>
        <depends>
        <Mage_Sales/>
        </depends>
    </Namespace_Audit>

then Create a folder Audit in you namespace and create the config file. purpose of this is to rewrite the core class and extending for modified method

app / code / local / Namespace / Audit / etc / config.xml

`<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Audit>
            <version>0.1.0</version>
        </Namespace_Audit>
    </modules>
     <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_view_tab_history before="Mage_Adminhtml_Block">Namespace_Audit_Block_Sales_Order_View_Tab_History<sales_order_view_tab_history>
                </rewrite>
            </adminhtml>
        </blocks>                    
        <global>
                <models>
                        <audit>
                                <class>Bigadda_Audit_Model</class>
                        </audit>
                </models>
        <resources>       
            <audit_setup>
                <setup>
                    <module>Bigadda_Audit</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </audit_setup>
            <audit_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </audit_write>
            <audit_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </audit_read>
        </resources>
        </global>
    </global>  
</config>`

create a setup to make a new attribute in database local / Namespace / Audit / sql / audit_setup / mysql4-install-0.1.0.php

`
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('order_status_history', 'track_user', array('type' => 'varchar'));
$installer->endSetup();
`

Now extending the existing class . create a class file History.php

Namespace/Audit/Block/Sales/Order/View/Tab/History

and copy the functions in that

` public function getFullHistory() { $order = $this->getOrder();

    $history = array();
    foreach ($order->getAllStatusHistory() as $orderComment){
        $history[$orderComment->getEntityId()] = $this->_prepareHistoryItem(
            $orderComment->getStatusLabel(),
            $orderComment->getIsCustomerNotified(),
            $orderComment->getCreatedAtDate(),
            $orderComment->getComment(),
            $orderComment->getTrackUser(),
            $orderComment->getTrackUserName()
        );
    }

    foreach ($order->getCreditmemosCollection() as $_memo){
        $history[$_memo->getEntityId()] =
            $this->_prepareHistoryItem($this->__('Credit Memo #%s created', $_memo->getIncrementId()),
                $_memo->getEmailSent(), $_memo->getCreatedAtDate());

        foreach ($_memo->getCommentsCollection() as $_comment){
            $history[$_comment->getEntityId()] =
                $this->_prepareHistoryItem($this->__('Credit Memo #%s comment added', $_memo->getIncrementId()),
                    $_comment->getIsCustomerNotified(), $_comment->getCreatedAtDate(), $_comment->getComment(),$_comment->getTrackUser(),$_comment->getTrackUserName());
        }
    }

    foreach ($order->getShipmentsCollection() as $_shipment){
        $history[$_shipment->getEntityId()] =
            $this->_prepareHistoryItem($this->__('Shipment #%s created', $_shipment->getIncrementId()),
                $_shipment->getEmailSent(), $_shipment->getCreatedAtDate());

        foreach ($_shipment->getCommentsCollection() as $_comment){
            $history[$_comment->getEntityId()] =
                $this->_prepareHistoryItem($this->__('Shipment #%s comment added', $_shipment->getIncrementId()),
                    $_comment->getIsCustomerNotified(), $_comment->getCreatedAtDate(), $_comment->getComment(),$_comment->getTrackUser(),$_comment->getTrackUserName());
        }
    }

    foreach ($order->getInvoiceCollection() as $_invoice){
        $history[$_invoice->getEntityId()] =
            $this->_prepareHistoryItem($this->__('Invoice #%s created', $_invoice->getIncrementId()),
                $_invoice->getEmailSent(), $_invoice->getCreatedAtDate());

        foreach ($_invoice->getCommentsCollection() as $_comment){
            $history[$_comment->getEntityId()] =
                $this->_prepareHistoryItem($this->__('Invoice #%s comment added', $_invoice->getIncrementId()),
                    $_comment->getIsCustomerNotified(), $_comment->getCreatedAtDate(), $_comment->getComment(),$_comment->getTrackUser(),$_comment->getTrackUserName());
        }
    }

    foreach ($order->getTracksCollection() as $_track){
        $history[$_track->getEntityId()] =
            $this->_prepareHistoryItem($this->__('Tracking number %s for %s assigned', $_track->getNumber(), $_track->getTitle()),
                false, $_track->getCreatedAtDate());
    }

    krsort($history);
    return $history;
}`

protected function _prepareHistoryItem($label, $notified, $created, $comment = '' , $trackUser = '' , $trackUserName ='')
    {
        return array(
            'title'      => $label,
            'notified'   => $notified,
            'track_user' => $trackUser,
            'track_user_name' => $trackUserName,
            'comment'    => $comment,
            'created_at' => $created            
        );
    }

extend the class order.php and add this method to set the comment to update the database. app / code / local / Mynamespace / Sales / Model / Order.php

public function addStatusHistoryComment($comment, $status = false)
        {
                if (false === $status) {
                        $status = $this->getStatus();
                } elseif (true === $status) {
                        $status = $this->getConfig()->getStateDefaultStatus($this->getState());
                } else {
                        $this->setStatus($status);
                }
                $UserInfo = Mage::getSingleton('admin/session')->getUser();
                $UserName='';
                $UserName=$UserInfo->getUsername();
                $history = Mage::getModel('sales/order_status_history')
                ->setStatus($status)
                ->setComment($comment)
                ->setTrackUser($UserName); //added by vipul dadhich to add audits in the 
                $this->addStatusHistory($history);
                return $history;

        }

finally updating the phtml files. app / design / adminhtml / default / default / template / sales / order / view / history.phtml place this code wherever u want to show the username

<?php if ($_item->getTrackUser()): ?>
                <br/><?php  echo "<b>Updated By ( User ) :-  </b>".$this->htmlEscape($_item->getTrackUser(), array('b','br','strong','i','u')) ?>
            <?php endif; ?>

app / design / adminhtml / default / default / template / sales / order / view / tab / history.phtml

 <?php if ($_comment = $this->getItemTrackUser($_item)): ?>
                    <br/><?php echo "<b>Updated By (User) :- </b>".$_comment ?>
                <?php endif; ?>

Thats All folks..

Vipul Dadhich

A different take by observing the event *sales_order_status_history_save_before*

Define the setup and observer in your config:

<config>
    <modules>
        <Name_Module>
            <version>0.0.1</version>
        </Name_Module>
    </modules>
    <global> 
        <resources>
            <module_setup>
                <setup>
                    <module>Name_Module</module>                    
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </module_setup>
        </resources>    
        <events>
            <sales_order_status_history_save_before> 
                <observers>
                    <sales_order_status_history_save_before_observer>
                        <type>singleton</type>
                        <class>Name_Module_Model_Observer</class>
                        <method>orderStatusHistorySaveBefore</method>
                    </sales_order_status_history_save_before_observer>
                </observers>
            </sales_order_status_history_save_before>    
        </events>
   <!-- and so on ->

In your module_setup file app/code/local/Name/Module/sql/module_setup/install-0.0.1.php

$installer = $this;
$installer->startSetup();
$table = $installer->getTable('sales/order_status_history');
$installer->getConnection()
    ->addColumn($table, 'username', array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'length'    => 40,
        'nullable'  => true,
        'comment'   => 'Admin user name'
    ));
$installer->getConnection()
    ->addColumn($table, 'userrole', array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'length'    => 50,
        'nullable'  => true,
        'comment'   => 'Admin user role'
    ));    
$installer->endSetup();

Then in Name_Module_Model_Observer:

public function orderStatusHistorySaveBefore($observer)  
{
    $session = Mage::getSingleton('admin/session');
    if ($session->isLoggedIn()) { //only for login admin user
        $user = $session->getUser();
        $history = $observer->getEvent()->getStatusHistory();
        if (!$history->getId()) { //only for new entry
            $history->setData('username', $user->getUsername());
            $role = $user->getRole(); //if you have the column userrole
            $history->setData('userrole', $role->getRoleName()); //you can save it too
        }            
    }
}