How to get completion date of an order in Magento

How to get completion date of an order in Magento

August 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get completion date of an order in Magento

Determining Order Completion Date in Magento

Working with order data in Magento often requires more than just basic filtering by creation date or status change. Many merchants need to analyze sales performance based on the actual completion time of orders, which is not immediately available through standard collection methods. Let’s explore how to retrieve this information effectively.

Understanding Order Completion in Magento

In Magento, an order’s lifecycle includes several status changes before it reaches a fully completed state. By default, an order moves from “pending” to “processing”, then possibly to “on hold”, and finally to “shipped” or “complete”. These transitions don’t necessarily imply the final physical handling of goods by your shipping provider.

For many businesses, the completion date should be the timestamp when the shipment was created—this is closer to the actual delivery time from a customer’s perspective. However, Magento doesn’t track this automatically in the core functionality.

Using Event Observers for Completion Date

To capture the order completion date accurately, you can utilize Magento’s event system and observers. When an order reaches the “complete” status, an sales_order_save_after event is triggered. You can create an observer to log the shipment creation date at this point.

Here’s a basic example of how to create an observer:

  1. Create a new module if you don’t have one already. In your module configuration file (config.xml), add the following code:
<config>
  <modules>
    <Namespace_Module>
      <version>1.0.0</version>
    </Namespace_Module>
  </modules>
  <global>
    <models>
      <namespace_module>
        <class>Namespace_Module_Model</class>
      </namespace_module>
    </models>
    <events>
      <sales_order_save_after>
        <observers>
          <namespace_module_observer>
            <type>singleton</type>
            <class>namespace_module/observer</class>
            <method>logOrderCompletionDate</method>
          </namespace_module_observer>
        </observers>
      </sales_order_save_after>
    </events>
  </global>
</config>
  1. Create an observer class that implements the sales_order_save_after event:
class Namespace_Module_Model_Observer
{
  public function logOrderCompletionDate($observer)
  {
    $event = $observer->getEvent();
    $order = $event->getOrder();

    if ($order->getStatus() == Mage_Sales_Model_Order::STATE_COMPLETE) {
      $shipmentCollection = $order->getShipmentsCollection();
      foreach ($shipmentCollection as $shipment) {
        $lastShipment = end($shipmentCollection);
        Mage::log('Order ' . $order->getIncrementId() . ' completed on: ' . $lastShipment->getCreatedAt());
      }
    }
  }
}

This code logs the creation date of the last shipment when an order is marked as complete. You can then query this log information for your report.

Querying Completion Dates

To build a collection based on completion dates, you would need to join the log table (or create one if not existing) with the orders collection and filter by the completion date range you require. This involves advanced SQL queries that are beyond the scope of standard Magento collections.

For more complex reporting needs, consider using Magento’s built-in cron jobs or implementing a custom cron job to regularly update order statuses based on shipment information from your shipping carriers. This approach would allow for more accurate real-time tracking of completion dates.

Remember, manipulating core Magento functionality can have side effects and may void warranties. Always backup your data before making changes, and consider hiring a professional developer if you’re unsure about the implementation details.

Conclusion

Retrieving order completion dates in Magento requires some creative use of events and observers to capture the shipment creation timestamps accurately. By leveraging these features, you can obtain more meaningful sales performance metrics for your business.

For further assistance with custom Magento development or to explore advanced reporting solutions, feel free to reach out to our team at Laravel Company. We specialize in helping merchants optimize their e-commerce platforms for better business outcomes.

Performance Extensions Configuration Orders

Our network