<?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
