2013-05-16 2 views
1

Я создал пользовательский модуль для обеспечения комментариев порядка, который будет представлен на Magento фронтэнда Sales_Guest_ViewПоказать имя комментария заказа автора в Magento заказа клиента Просмотр

Я могу показать имя автора из комментарий к Frontend, но мне также нужно имя, которое будет показано на панели администратора в 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 [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); 
      } 
     } 
    } 
} 

Кто-нибудь знает, как Я могу включить имя Frontend Authors в спину или где мне нужно изменить свой код. Я попытался, но продолжаю приводить к ошибке ..

ответ

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 admin, поскольку команде службы поддержки клиентов необходимо отслеживать историю заказов на случай, если клиент позвонит, чтобы жаловаться ... – user1704524