将用户名添加到评论历史 Magento 1.9

Adding username to comment history Magento 1.9

我想在我的评论历史记录中添加首字母。比如用户名会自动显示在评论中,因此用户无需手动输入。它只会显示他们自己的用户名。

我在这个问题上找到了两个指南。但是,它只适用于 Magento 1.4 和 Magento 1.7。我更改了他们指南中的文件后,它仍然无法正常工作。

有办法实现吗?

我添加到我的代码中的东西:

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

您需要创建简单的模块并编写以下代码

app/code/local/Modulenamespace/Modulename/etc/config.xml

<adminhtml>
        <events>
            <controller_action_predispatch_adminhtml_sales_order_addComment>
                <observers>
                    <modulenamespace_modulename_unique_node>
                        <class>Your_Module_Model_Observer</class>
                        <method>controllerActionPredispatchAdminhtmlSalesOrderAddComment</method>
                    </modulenamespace_modulename_unique_node>
                </observers>
            </controller_action_predispatch_adminhtml_sales_order_addComment>
            <controller_action_predispatch_adminhtml_sales_order_creditmemo_save>
                <observers>
                    <modulenamespace_modulename_unique_node>
                        <class>Your_Module_Model_Observer</class>
                        <method>controllerActionPredispatchAdminhtmlSalesOrderCreditmemoSave</method>
                    </modulenamespace_modulename_unique_node>
                </observers>
            </controller_action_predispatch_adminhtml_sales_order_creditmemo_save>
            <controller_action_predispatch_adminhtml_sales_order_creditmemo_addComment>
                <observers>
                    <modulenamespace_modulename_unique_node>
                        <class>SSD_Authorizenetcim_Model_Observer</class>
                        <method>controllerActionPredispatchAdminhtmlSalesOrderCreditmemoAddComment</method>
                    </modulenamespace_modulename_unique_node>
                </observers>
            </controller_action_predispatch_adminhtml_sales_order_creditmemo_addComment>
        </events>
    </adminhtml>

/app/code/local/Modulenamespace/Modulename/Model/Observer.php

function controllerActionPredispatchAdminhtmlSalesOrderAddComment($observer)
{
    $history = Mage::app()->getRequest()->getPost('history');
    if ($history && isset($history['comment'])) {
        $history['comment'] .= $this->_getAppend();
        Mage::app()->getRequest()->setPost('history', $history);
    }
}
function controllerActionPredispatchAdminhtmlSalesOrderCreditmemoSave($observer)
{
    $post = Mage::app()->getRequest()->getPost('creditmemo');
    if ($post && isset($post['comment_text'])) {
        $post['comment_text'] .= $this->_getAppend();
        Mage::app()->getRequest()->setPost('creditmemo', $post);
    }
}
function controllerActionPredispatchAdminhtmlSalesOrderCreditmemoAddComment($observer)
{
    $post = Mage::app()->getRequest()->getPost('comment');
    if ($post && isset($post['comment'])) {
        $post['comment'] .= $this->_getAppend();
        Mage::app()->getRequest()->setPost('comment', $post);
    }
}
protected function _getAppend()
{
    $user     = Mage::getSingleton('admin/session');
    $username = $user->getUser()->getUsername();
    return "<br/><br/> Posted by: " . $username;
}