Question

My code :

<?php 

require_once('app/Mage.php');
umask(0);
Mage::app();


// try{

$orders = Mage::getModel('sales/order')->load('10');
foreach ($orders as $order) {
    $orderComments = $order->getAllStatusHistory();
    print_r($orderComments);

    }

// }catch(Exception $e){
//  echo $e->getMessage();
// }

How to get Comments History of the order?

Status : Pending-> Processing-> Awaiting Shipment-> Shipped-> Complete

Was it helpful?

Solution

Please check below code

<?php 
    require_once('app/Mage.php');
    umask(0);
    Mage::app();

    $order = Mage::getModel('sales/order')->load(10);
    $statusHistory = $order->getStatusHistoryCollection()->getData();
    echo "<pre>";
    print_r($statusHistory);
?>

To show only status,created_at, entity_name Please check below code.

<?php 
    require_once('app/Mage.php');
    umask(0);
    Mage::app();

    $orderStatuses = Mage::getModel('sales/order')->load(10)->getStatusHistoryCollection()->getData();
    foreach ($orderStatuses as $orderStatus) {
        echo "Status = ".$orderStatus['status']."<br>";
        echo "Created At = ".$orderStatus['created_at']."<br>";
        echo "Entity Name = ".$orderStatus['entity_name']."<br><br>";
    }
?>

You get output like below array.

enter image description here

Hope it will work for you.

OTHER TIPS

<?php 


require_once('app/Mage.php');
umask(0);
Mage::app();


    function prepareHistoryItem($label, $notified, $created, $comment = '')
{
    return array(
        'title'      => $label,
        'notified'   => $notified,
        'comment'    => $comment,
        'created_at' => $created
    );
}

try{
    $history = array();
    $order = Mage::getModel('sales/order')->load('1765');
    foreach ($order->getAllStatusHistory() as $orderComment){
        $history[] = prepareHistoryItem(
            $orderComment->getStatusLabel(),
            $orderComment->getIsCustomerNotified(),
            $orderComment->getCreatedAtDate(),
            $orderComment->getComment()
        );
    }
    foreach ($order->getCreditmemosCollection() as $_memo){
        $history[] = prepareHistoryItem(
            sprintf(__('Credit memo #%s created', $_memo->getIncrementId())),
            $_memo->getEmailSent(),
            $_memo->getCreatedAtDate()
        );

        foreach ($_memo->getCommentsCollection() as $_comment){
            $history[] = prepareHistoryItem(
                sprintf(__('Credit memo #%s comment added', $_memo->getIncrementId())),
                $_comment->getIsCustomerNotified(),
                $_comment->getCreatedAtDate(),
                $_comment->getComment()
            );
        }
    }

    foreach ($order->getShipmentsCollection() as $_shipment){
        $history[] = prepareHistoryItem(
            sprintf(__('Shipment #%s created', $_shipment->getIncrementId())),
            $_shipment->getEmailSent(),
            $_shipment->getCreatedAtDate()
        );

        foreach ($_shipment->getCommentsCollection() as $_comment){
            $history[] = prepareHistoryItem(
                sprintf(__('Shipment #%s comment added', $_shipment->getIncrementId())),
                $_comment->getIsCustomerNotified(),
                $_comment->getCreatedAtDate(),
                $_comment->getComment()
            );
        }
    }

    foreach ($order->getInvoiceCollection() as $_invoice){
        $history[] = prepareHistoryItem(
            sprintf(__('Invoice #%s created', $_invoice->getIncrementId())),
            $_invoice->getEmailSent(),
            $_invoice->getCreatedAtDate()
        );

        foreach ($_invoice->getCommentsCollection() as $_comment){
            $history[] = prepareHistoryItem(
                sprintf(__('Invoice #%s comment added', $_invoice->getIncrementId())),
                $_comment->getIsCustomerNotified(),
                $_comment->getCreatedAtDate(),
                $_comment->getComment()
            );
        }
    }

    foreach ($order->getTracksCollection() as $_track){
        $history[] = prepareHistoryItem(
            sprintf(__('Tracking number %s for %s assigned', $_track->getNumber(), $_track->getTitle())),
            false,
            $_track->getCreatedAtDate()
        );
    }
    echo '<pre>';print_r($history);
} catch (Exception $e){
    echo $e->getMessage();
}

The output is like enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top