Magento – Create Part Shipment and Check Item Shipping Status

ordersshipmentshipping

Is it possible in Magento to ship single items of an order independently of each other programatically?

For example, say i have an order with 5 order items and i want to ship only 1 of those how can this be done?

Additionally, i would like to determine if any of the single items has been shipped.

Best Answer

Yes, it's possible.

Manually

Go to the order, generate shipment, and then enter the # of qty/items to ship in that particular shipment.

enter image description here

The order will remain in Processing or your custom status until all items have been shipped before it will be marked as Completed.

Programmatically

$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(
    array(
      'order_item_id'=>1,
      'order_item_id'=>4,
      'order_item_id'=>2
    )
);

There are several ways to check if an item has been shipped

1) Look at the order item's qty_shipped value:

foreach($order->getAllItems() as $item){
    echo $item->getQtyShipped();
}

2) Look at the order item status:

$item->getStatus();

To get more information on how a status is determined (it's not a stored value, it's derived) see this class:

https://github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/code/core/Mage/Sales/Model/Order/Item.php#L194


More reading about generating shipments programmatically:

Programmatically Creating Shipments

Related Topic