Magento: not shipped item collection

Magento: not shipped item collection

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: not shipped item collection

Retrieving Unshipped Items for a Magento Order

When dealing with partial shipments in Magento, you often need to retrieve all unshipped items for an order. This is particularly useful when you want to handle backorders or have a complex shipping process involving multiple carriers.

Understanding the Problem Scenario

Let’s say you have an order that contains several products, and some of those products have already been shipped while others are still pending. You want to query all unshipped items for that specific order so you can process them separately.

The challenge is to construct a Magento collection that includes only the unshipped items for the given order ID.

Building the Unshipped Items Collection

To achieve this, we’ll use the Mage::getModel function to get an instance of the order model and then retrieve its items. We’ll filter the results using a custom query.

First, make sure you have loaded your order object:

$order = Mage::getModel('sales/order')->load($orderId);

Next, we create a collection of all order items for this specific order:

$itemCollection = $order->getItemsCollection();

Now, we need to filter out the already shipped items. For an item to be considered “unshipped”, its qty_shipped property must be 0.

We can use the addFieldToFilter method for this purpose:

$itemCollection->addFieldToFilter('qty_shipped', array(
    'eq' => 0,
));

Retrieving the Actual Items

The $itemCollection now contains only the items that haven’t been shipped yet. To get an array of these items, you can use:

$unshippedItems = $itemCollection->getItems();

Each element in this array is a Varien_Object representing one unshipped item.

Working with the Unshipped Items

Now that we have our collection of unshipped items, there are several things you can do:

  • Count the unshipped items: $unshippedItemsCount = count($unshippedItems);

  • Loop through the items for further processing: foreach ($unshippedItems as $item) { … }

  • Access item properties like name, quantity, price, etc.: $item->getName(), $item->getQty(), $item->getPrice()

Conclusion

Retrieving unshipped items in Magento is a critical operation when you need to handle partial shipments or backorders. By using the addFieldToFilter method on the order item collection, we can efficiently filter out already shipped items.

Remember that this approach works for standard Magento installations. If you have customizations or additional plugins installed, there might be other considerations to take into account.

For more in-depth tutorials and best practices on Magento development, feel free to explore the resources available at Laravel Company. We cover topics from e-commerce integrations to advanced customization techniques.

Catalog Database Orders Errors

Our network