Editing Magento Order Comments in Admin
If you’re running Magento version 1.7.0.2 and need to edit or remove order comments from the admin panel, you’ve come to the right place. This can indeed be achieved with a bit of customization.
Understanding the Current Setup
In Magento’s default configuration, order comments are added by customers during checkout or through the sales order view on the frontend. These comments are stored in the sales_flat_order_status_history and core_comment tables in your database.
Currently, there is no built-in functionality to edit these comments directly from the admin panel. However, we can create a custom extension to accomplish this task.
Creating a Custom Module
To start, let’s create a new module called “SalesCommentAdminEdit.” This module will provide an interface for editing order comments in the admin panel.
- Configuration File (app/etc/modules/SalesCommentAdminEdit.xml):
<?xml version="1.0"?>
<config>
<modules>
<SalesCommentAdminEdit>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Sales />
</depends>
</SalesCommentAdminEdit>
</modules>
</config>
- Module Configuration File (app/code/local/SalesCommentAdminEdit/etc/config.xml):
<?xml version="1.0"?>
<config>
<modules>
<SalesCommentAdminEdit>
<version>1.0.0</version>
</SalesCommentAdminEdit>
</modules>
<global>
<resources>
<sales_comment_admin_edit_setup>
<setup>
<module>SalesCommentAdminEdit</module>
<version>1.0.0</version>
</setup>
</sales_comment_admin_edit_setup>
</resources>
<models>
<sales_comment_admin_edit>
<class>SalesCommentAdminEdit_Model</class>
<resourceModel>sales_comment_admin_edit_resource</resourceModel>
</sales_comment_admin_edit>
</models>
<helpers>
<sales_comment_admin_edit>
<class>SalesCommentAdminEdit_Helper</class>
</sales_comment_admin_edit>
</helpers>
</global>
</config>
- Creating the Setup Script (app/code/local/SalesCommentAdminEdit/sql/sales_comment_admin_edit_setup/install-1.0.0.0.php):
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE IF NOT EXISTS `sales_flat_order_status_history` (
`entity_id` int(255) NOT NULL auto_increment,
`parent_id` int(10) unsigned NOT NULL default '0',
`status` varchar(32) NOT NULL default '',
`comment` text default NULL,
`created_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
)
ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Order status history';
");
$installer->endSetup();
- Creating the Admin Grid (app/code/local/SalesCommentAdminEdit/controllers/Adminhtml/Sale/OrderController.php):
public function commentsAction()
{
$this->_title($this->__('Sales'))->_title($this->__('Manage Comments'));
// Your code to retrieve and display order comments in a grid
$this->renderLayout();
}
- Creating the Comment Edit Form (app/code/local/SalesCommentAdminEdit/Block/Adminhtml/Sale/Order/Comments.php):
public function getFormAction()
{
return $this->getUrl('*/*/save', array('entity_id' => $this->getRequest()->getParam('entity_id')));
}
public function getSubmitLabel()
{
return Mage::helper('sales_comment_admin_edit')->__('Save Comment');
}
Updating the Frontend
To update the customer view of the order comments, you can override the order view template file located at app/design/frontend/default/default/template/sales/order/view.phtml. Update this file to reflect the changes made in the admin panel.
Conclusion
Editing Magento order comments in the admin panel is a non-trivial task that requires creating a custom extension and modifying the database structure. This process involves creating a new module, adding the necessary setup scripts, and developing the admin grid and edit form.
While this is a complex task for version 1.7.0.2 of Magento, it demonstrates the flexibility of the platform and the ability to create custom functionality using the built-in extension system.
For more information on Magento’s core functionality and how to extend it, I recommend checking out Laravel Company, a leading provider of Magento development services and resources.