2013-05-16 54 views
1

我創建了一個自定義模塊,以允許在Magento的前端 Sales_Guest_View在Magento的銷售訂單顯示訂單評論作者的名字查看

我能夠顯示的作者的名字將被提交訂單評論評論前端,但我也需要在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'); 
      } 
     } 
    } 

} 

和管理控制器,它只能說明,提交的評論管理員的名稱

<?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 [email protected] 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); 
      } 
     } 
    } 
} 

有誰知道怎麼形成的前端控制器我可以在後面或我需要修改代碼的地方包含前端作者名稱。我曾嘗試過,但一直導致一個錯誤..

回答

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(); 
} 
+0

基本上,我已經建立了一個callcentre應用對於Magento來說,它使用類似的前端佈局和模板結構來下訂單。唯一的區別是CallCenter代理必須登錄到通過電話訂購的網站。如果代理商添加評論,我將需要它反映在Magento管理員中,因爲客戶服務團隊需要跟蹤訂單歷史記錄,以防客戶打來抱怨... – user1704524

相關問題