将用户名添加到订单注释历史记录 [英] Add Username to Order Comment History

查看:62
本文介绍了将用户名添加到订单注释历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以将在管理历史记录中发表评论的人的用户名添加到订单的评论线程中?

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?

-编辑-

另一种询问方式是如何在注释历史记录模型中添加一个附加字段,以便可以覆盖将数据插入数据结构的适当模型和模板.

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添加属性.

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.

创建一个模块,说审核 app/etc/modules/Namespace_Audit.xml

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

<?xml version="1.0"?> 
<config> 
    <modules>
        <Namespace_Audit>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales/>
            </depends>
        </Namespace_Audit>
    </modules>
</config>

然后在名称空间中创建一个文件夹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

应用程序/代码/本地/命名空间/审核/等/config.xml

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>`

创建一个设置以在数据库中创建新属性 本地/命名空间/审核/sql/audit_setup/mysql4-install-0.1.0.php

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();
`

现在扩展现有的类.创建一个类文件History.php

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

名称空间/审核/块/销售/订单/视图/制表符/历史记录

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

并复制其中的功能

` 公共函数getFullHistory() { $ order = $ this-> getOrder();

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

扩展class order.php并添加此方法来设置注释以更新数据库. 应用程序/代码/本地/Mynamespace/销售/模型/Order.php

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;

        }

最终更新phtml文件. 应用程序/设计/adminhtml/默认/默认/模板/销售/订单/视图/history.phtml 将此代码放置在您想要显示用户名的任何地方

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

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

那是所有人.

Vipul Dadhich

Vipul Dadhich

这篇关于将用户名添加到订单注释历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆