I suppose you have increment_id of order. Or may be you have order_id of order you can load order using both. So next  if you want to get all comment of that order or last comment. Below code will 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.
// print_r($allComments);die;
$lastCommentOfOrder = reset($allComments); // Array of last comment, if you wana check uncomment next line.
// 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 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

Happy to help.

Be kind to one another. Take care!

No Comments

Post A Comment