I have created a module that adds the username of the logged in admin that adds a comment to an order. I now need to add this feature for Creditmemo but have hit a brick a wall.
Here's my code for order comment:
Controller
<?php require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php'; class MyModule_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 = ".<br /> <br /> 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'] : true; //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); } } } } And I have added this code to Adminhtml/Sales/Order/View/history.phtml
<?php if ($_item->getComment()): ?> <br/><?php echo $this->escapeHtml($_item->getComment(), array('b','br','strong','i','u')) ?> <?php endif; ?> And this to Adminhtml/Sales/Order/View/Tab/history.phtml
<?php if ($_comment = $this->getItemComment($_item)): ?> <br/><?php echo $_comment ?> <?php endif; ?> Now my question is how do I amend the logic to do this for credit meme page?
Inside the same module Can I create a CreditmemoController.php? Could anyone tell me how/where I should alter the logic for Credit meme please?
Thanks guys...
Changed my config.xml file
<?xml version="1.0"?> <config> <modules> <MyModule_OrderComment> <version>0.0.1</version> </MyModule_OrderComment> </modules> <admin> <routers> <adminhtml> <!--args> <modules> <MyModule_OrderComment_Adminhtml before="Mage_Adminhtml">MyModule_OrderComment_Adminhtml</MyModule_OrderComment_Adminhtml> </modules> </args--> <events> <controller_action_predispatch_adminhtml_sales_order_addComment> <observers> <ordercomment> <class>MyModule_OrderComment_Model_Observer</class> <method>controllerActionPredispatchAdminhtmlSalesOrderAddComment</method> </your_module_unique_node> </ordercomment> </controller_action_predispatch_adminhtml_sales_order_addComment> <controller_action_predispatch_adminhtml_sales_order_creditmemo_save> <observers> <ordercomment> <class>MyModule_OrderComment_Model_Observer</class> <method>controllerActionPredispatchAdminhtmlSalesOrderCreditmemoSave</method> </ordercomment> </observers> </controller_action_predispatch_adminhtml_sales_order_creditmemo_save> <controller_action_predispatch_adminhtml_sales_order_creditmemo_addComment> <observers> <ordercomment> <class>MyModule_OrderComment_Model_Observer</class> <method>controllerActionPredispatchAdminhtmlSalesOrderCreditmemoAddComment</method> </ordercomment> </observers> </controller_action_predispatch_adminhtml_sales_order_creditmemo_addComment> </events> </adminhtml> </routers> </admin> <global> <helpers> <exgrid> <class>MyModule_OrderComment_Helper</class> </exgrid> </helpers> </global> </config> Added new Oberver.php to MyModule/OrderComment/Model/
<?php //class MyModule_OrderComment_Model_Observer function controllerActionPredispatchAdminhtmlSalesOrderAddComment($observer) { $history = Mage::app()->getRequest()->getPost('history'); if ($history && isset($history['comment'])) { $history['comment'] .= $this->_getAppend(); Mage::app()->getRequest()->setPost('history', $history); } } function controllerActionPredispatchAdminhtmlSalesOrderCreditmemoSave($observer) { $post = Mage::app()->getRequest()->getPost('creditmemo'); if ($post && isset($post['comment_text'])) { $post['comment_text'] .= $this->_getAppend(); Mage::app()->getRequest()->setPost('creditmemo', $post); } } function controllerActionPredispatchAdminhtmlSalesOrderCreditmemoAddComment($observer) { $post = Mage::app()->getRequest()->getPost('comment'); if ($post && isset($post['comment'])) { $post['comment'] .= $this->_getAppend(); Mage::app()->getRequest()->setPost('comment', $post); } } protected function _getAppend() { $user = Mage::getSingleton('admin/session'); $username = $user->getUser()->getUsername(); return "<br/><br/> Posted by: " . $username; } Removed my controller folder which contains OrderController.php
Have I done something incorrectly?