Magento Order History Comments: Modify Date

Magento Order History Comments: Modify Date

July 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Order History Comments: Modify Date

Solving Magento Order History Comments Date Issue

Are you facing challenges while programmatically modifying dates of order history comments in your Magento store? You’re not alone! In this post, we’ll dive into a common issue related to changing the date of entries in the Comments History (like quote, invoice, shipping) and provide a comprehensive solution.

Understanding the Problem

When creating orders programmatically in Magento, you might successfully manipulate the order creation date using setCreatedAt. However, modifying dates for specific comments within the history remains elusive. For instance, when using methods like addStatusHistoryComment, the comment date defaults to the current system time instead of your desired date.

Analyzing Your Code Snippet

You’ve provided an excellent starting point with your code snippet:

$shipment->setCreatedAt('2008-09-23 14:20:10');
$order->addStatusHistoryComment('Shipping message goes here...', true);

The issue lies in the timing. By default, Magento records the current time when adding a status history comment, overshadowing your specified setCreatedAt date.

The Elegant Solution

To solve this puzzle, we need to dive into the core of Magento’s order history management. The key lies in understanding how Magento processes and saves data during the transaction process.

Step 1: Modify the Invoice and Shipment Objects

Ensure that before saving your invoice or shipment objects, you have already set the desired dates using setCreatedAt method:

$invoice->setCreatedAt('2008-09-23 14:20:10');
$shipment->setCreatedAt('2008-09-23 15:30:20');

Step 2: Separate the Comment Addition

The critical step is to separate the comment addition process from the object save. Magento’s addStatusHistoryComment method automatically registers the current system time when saving the comment.

To work around this, we’ll create a custom status history comment model and manually set its date:

$status = Mage::getModel('sales/order_status_history');
$status->setComment('Shipping message goes here...')
       ->setEntityName($shipment->getEntityName())
       ->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING)
       ->setCreatedAt('2008-09-23 15:35:45');

Step 3: Save the Comment Manually

Now, let’s save this custom status history comment manually:

$status->save();

After saving the manual comment, we need to update the related order’s status history collection as well:

$shipment->getOrder()->setStatusHistoryCollection(
    Mage::getResourceModel('sales/order_status_history_collection')
        ->addFieldToFilter('status_history_id', $status->getId())
);

Step 5: Save the Transaction

Finally, save your transaction to commit all changes:

$transactionSave->save();

Conclusion

Modifying order history comments’ dates in Magento programmatically requires a deeper understanding of the data flow and management. By separating the comment addition process from the object save and manually setting the desired dates, we can effectively override Magento’s default behavior.

Remember to test this solution thoroughly in your development environment before deploying it to your live store.

For more advanced Magento customizations and best practices, don’t forget to explore LaravelCompany. We provide comprehensive guides and tutorials on Magento 2 development, helping you unlock the full potential of your e-commerce platform.

Orders Errors

Our network