0

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;
}
2

Instead of above static code you can also check for current controller and module. Like if it is sales module and order controller running then run your custom code other wise run default code.

if($this->getRequest()->getControllerName() == 'sales_order'){
    $status = $this->getStatus();
else{
   //default code
}
  • That is brilliant, much cleaner then my solution. Thanks for the help mate. – iamlolz Mar 9 '17 at 2:32
  • welcome dear... – Gulshan Mar 9 '17 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.