1

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

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

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

这是显示作者姓名的表单的前端控制器

<?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');
            }
        }
    }

}

以及仅显示提交评论的管理员名称的管理员控制器

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

有谁知道我如何在后面包含前端作者的名字或者我需要修改我的代码的地方。我尝试过但一直导致错误..

4

1 回答 1

1

我不是 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();
 }
于 2013-05-16T13:52:32.113 回答