在Magento销售订单视图中显示订单评论作者的姓名


Show the name of order comment author in Magento Sales Order View

我创建了一个自定义模块,允许在Magento前端提交订单评论Sales_Guest_View

我能够在前端上显示评论作者的姓名,但我还需要在Sales_Order_View的管理面板中显示该名称。

原因是在Magento管理中跟踪订单评论等。

下面是显示作者名称

的表单的前端控制器
<?php
require_once Mage::getModuleDir('Controller', 'Mage_Sales') . DS . 'Controller' . DS . 'Abstract.php';
class Tamedo_FrontendOrderMessage_FormController extends Mage_Sales_Controller_Abstract {
    protected $_guest_cookieName  = 'guest-view';
    protected $_guest_lifeTime    = 600;
    public function orderAction() {
        if(Mage::getSingleton('customer/session')->isLoggedIn()) {
            $this->_loadValidOrder();
        } else {
            Mage::helper('sales/guest')->loadValidOrder();
        }
        $order = Mage::registry('current_order');
        $orderId = $order->getId();
        if(empty($orderId)) {
            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $this->_redirect('sales/order/history');
            } else {
                $this->_redirect('sales/guest/form');
            }
        } else {
            $data = $this->getRequest()->getParams();
            if (!empty($data['history']['comment']))
                $append = " Posted By: ".$username.""; {
                $order->addStatusHistoryComment($data['history']['comment'], false)
                        ->setIsVisibleOnFront(true)
                        ->setIsCustomerNotified(false);
                $order->save();
            }
            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $this->_redirect('sales/order/view', array('order_id' => $order->getId()));
            } else {
                $toCookie = base64_encode($order->getProtectCode());
                Mage::getSingleton('core/cookie')->set($this->_guest_cookieName, $toCookie, $this->_guest_lifeTime, '/');
                $this->_redirect('sales/guest/view');
            }
        }
    }
}

和Admin Controller,它只显示提交评论的Admin的名字

<?php
/**
 * Tamedo
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category    Atwix
 * @package     Atwix_OrderComment
 * @author      Atwix Core Team
 * @copyright   Copyright (c) 2012 Atwix (http://www.atwix.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
class Tamedo_OrderComment_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
    /**
     * Add order comment action
     */
    public function addCommentAction()
    {
        if ($order = $this->_initOrder()) {
            try {
                $response = false;
                 //getting username
                $user = Mage::getSingleton('admin/session');
                $username = $user->getUser()->getUsername();
                $append = " posted by: ".$username."";
                $data = $this->getRequest()->getPost('history');
                $notify = isset($data['is_customer_notified']) ? $data['is_customer_notified'] : false;
                $visible = isset($data['is_visible_on_front']) ? $data['is_visible_on_front'] : false;

                //appending username with markup to comment
                $order->addStatusHistoryComment($data['comment'].$append, $data['status'])
                    ->setIsVisibleOnFront($visible)
                    ->setIsCustomerNotified($notify);
                $comment = trim(strip_tags($data['comment']));
                $order->save();
                $order->sendOrderUpdateEmail($notify, $comment);
                $this->loadLayout('empty');
                $this->renderLayout();
            }
            catch (Mage_Core_Exception $e) {
                $response = array(
                    'error'     => true,
                    'message'   => $e->getMessage(),
                );
            }
            catch (Exception $e) {
                $response = array(
                    'error'     => true,
                    'message'   => $this->__('Cannot add order history.')
                );
            }
            if (is_array($response)) {
                $response = Mage::helper('core')->jsonEncode($response);
                $this->getResponse()->setBody($response);
            }
        }
    }
}

有谁知道我怎么能包括前端作者的名字在后面或在哪里我需要修改我的代码。

我不是100%确定你要做什么,但你可以尝试使用用户名的订单计费或发货名称或获得当前登录的用户信息。

从会话

获取客户名
$username = Mage::getSingleton('customer/session')->getCustomer()->getName()

从订单中获取客户信息

$username = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname()

然后将代码更新为

.....
if (!empty($data['history']['comment']))
    $comment = $data['history']['comment'] . " Posted By: {$username}."; {
    $order->addStatusHistoryComment($comment, false)
          ->setIsVisibleOnFront(true)
          ->setIsCustomerNotified(false);
    $order->save();
 }