WonderLand WonderLand - 6 months ago 25
SQL Question

Magento: not shipped item collection

I would like to get all items that has not been shipped for a given order.

Suppose that I have a partial shipped order I would like to retrieve all items that are pending to be shipped.

Something like:

$collection = Mage::getModel('...')->getCollection()
->Add...()

Answer
$orderId = 382;

$order = Mage::getModel('sales/order')->load($orderId);
// OR if you load the order with increment id ...
// $order = Mage::getModel('sales/order')->loadByIncrementId($orderId); 
$orderItems = $order->getItemsCollection();

foreach ($orderItems as $item) {

    $qtyToBeShipped = $item->getQtyOrdered() - $item->getQtyShipped();

    if ($qtyToBeShipped)
        echo $item->getId() . ' - ' . $qtyToBeShipped . '</br>';
}