I've created a module to rewrite the function addCommentAction in app/code/core/Mage/Sales/Model/Order.php but I want the default core addCommentAction function to be used when called from a different module that I'd rather not modify.
Essentially I am disabling the order status update functionality in the order comment history area, but I don't want it disabled when our third party extension(Aitoc) calls the same method to do bulk updates from the order grid.
I have achieved this with the below rewrite which checks which file called the method, but I'm sure there is a much better way to achieve this. My ugly solution at this point is:
public function addStatusHistoryComment($comment, $status = false)
{
// store filename used to call method from order view
$orderViewFilename = '/ebs1/html/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php';
// store actual parent filename
$actualParentFilename = debug_backtrace()[0]['file'];
// check what the filename is
switch($actualParentFilename) {
case $orderViewFilename:
// comment history update ignores status update
$status = $this->getStatus();
break;
default:
// other updates continue as normal
if (false === $status) {
$status = $this->getStatus();
} elseif (true === $status) {
$status = $this->getConfig()->getStateDefaultStatus($this->getState());
} else {
$this->setStatus($status);
}
}
// update order status and save comment
$history = Mage::getModel('sales/order_status_history')
->setStatus($status)
->setComment($comment)
->setEntityName($this->_historyEntityName);
$this->addStatusHistory($history);
return $history;
}