How to check if a order has a shipment in Magento?

How to check if a order has a shipment in Magento?

October 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to check if a order has a shipment in Magento?

Checking for Existing Shipments in Magento Orders

As a senior developer working extensively with e-commerce platforms, I often encounter scenarios where we need to check if an order in Magento has already been shipped. The question posed highlights the challenge of getting shipment information using only the order increment ID.

Understanding Magento’s Order and Shipment Structure

In Magento, orders and shipments are connected through their respective IDs and entities. When a shipment is created for an order, it is linked to that specific order. To retrieve shipment data, we need to navigate from the order object to its associated shipments.

Retrieving Existing Shipments from an Order

To get a list of all shipments associated with an order, you can use the getShipmentsCollection method provided by the sales/order_shipment model. Here’s how to achieve this:

$order = Mage::getModel('sales/order')->loadByIncrementId($order_increment_id);
if ($order->getId()) {
    $shipments = Mage::getResourceModel('sales/order_shipment_collection')
        ->addFieldToFilter('order_id', $order->getId())
        ->load();

    if (count($shipments) > 0) {
        // You now have access to all shipments for this order
        foreach ($shipments as $shipment) {
            // Access shipment data, e.g.
            echo 'Shipment ID: ' . $shipment->getId() . '<br>';
            echo 'Shipment Increment ID: ' . $shipment->getIncrementId() . '<br>';
        }
    } else {
        echo 'No shipments found for this order.';
    }
} else {
    echo 'Order not found.';
}

In this code, we first load the order by its increment ID. We then create a shipment collection filtered by the order_id equal to our loaded order’s ID and load it into memory.

The resulting $shipments object is an array of all shipments associated with that specific order. You can then iterate through each shipment in the collection, accessing relevant data such as the shipment’s increment ID or other custom attributes you might have added.

Conclusion: Navigating Magento’s Object-Oriented Architecture

This example demonstrates how to navigate from a loaded order object to its related shipments using Magento’s built-in models and resource collections. By understanding the relationships between these objects, we can efficiently retrieve associated data without needing the specific shipment increment ID upfront.

Remember that this code snippet assumes you are in a Magento context where Mage:: is available. If you’re working outside of the Magento framework or with an API, you’ll need to adapt the approach accordingly, possibly using Magento’s SOAP or REST APIs to load orders and shipments.

For more detailed information on Magento’s order and shipment management features, I recommend checking out the official documentation at https://laravelcompany.com/magento-development-resources.

Orders

Our network