In magento if you want to get specific order’s all comment or last commet this code can help you to do that.


$incrementId = 145000251; // Order's incrementId
$orderdata = Mage::getModel('sales/order')->load($incrementId, 'increment_id'); // Load that order by incrementId
$comments = $orderdata->getStatusHistoryCollection(true); // Collection of comments on that order
$allComments = $comments->getData(); // Array of all comments, if you wana check uncomment next line.
// echo "<pre>";print_r($allComments);die;
$lastCommentOfOrder = reset($allComments); // Array of last comment, if you wana check uncomment next line.
// echo "<pre>";print_r($lastCommentOfOrder);die;
echo $lastCommentOfOrder['comment']; // Here is last comment on this order

Just in case if you want to insert new comment into specific order. Let me show that also it’s very simple.

$comment = "New Comment by vky"; // your comment
$incrementId = 145000251; // incrementId of order in which you want to add new comment
$order = Mage::getModel('sales/order')->load($incrementId, 'increment_id'); // Load that order
$order->addStatusHistoryComment($comment); // Add your comment
$order->save(); // save order

 

Leave a Reply