Если вы хотите добавить имя пользователя, который в данный момент вошел в систему и вносит изменения в заказ или комментирует заказ.вам нужно добавить атрибут в magento.
Создать модуль, скажем, 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 в вашем пространстве имен и создать конфигурациюфайл.Цель этого состоит в том, чтобы переписать базовый класс и расширение для модифицированного метода
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>`
создать установку, чтобы сделатьновый атрибут в базе данных 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
Пространство имен / Аудит / Блок / Продажи / Заказ / Вид / Вкладка / История
и скопируйте функции в этой
`публичной функции 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
);
}
расширить класс order.php и добавить этот метод, чтобы задать комментарий для обновления базы данных.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.app / design / adminhtml / default / default / template / sales / order / view / history.phtml разместите этот код там, где вы хотите показать имя пользователя
<?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 people ..
Vipul Dadhich