I wanna get the number of items that has been shipped in a Magento order. For example, a person orders 10 items. 4 has been shipped. I wanna get the number 4 in this case, then combine with the rest of 6 items which is on a second shipping batch. Check if 4 + 6 equals total number of items 10, if the second shipping batch shipped out all 6, change the order status to Complete. If not, change to Partial Shipment.
3
votes
1 Answers
6
votes
$order = Mage::getModel('sales/order')->load($orderId);
$total_ordered_items = $order->getData('total_qty_ordered');
$num_of_shipped_items = 0;
foreach ($order->getAllVisibleItems() as $item){
//$item->getQtyOrdered() // Number of item ordered
$num_of_shipped_items += $item->getQtyShipped();
//$item->getQtyInvoiced()
}
if($num_of_shipped_items == $total_ordered_items){
// set status to complete
}
else{
// Partial
}