2

Using Magento EE 1.9, I've enabled backorders, but there's no way to see if an order contains backordered items in the Sales/Orders grid view.

How would I check if an item was backordered or not after an order has been placed?

(Code-based solutions are fine.)

1 Answer 1

2

Something like this maybe:

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

    foreach ($orderItems as $orderItem) {
        $sumBackordered = 0;
        $children = array();

        if ($orderItem->getHasChildren()) {
            foreach ($orderItem->getChildrenItems() as $childItem) {
                $sumBackordered += (float)$childItem->getQtyBackordered();
                $children[] = array(
                    'name'              => $childItem->getName(),
                    'qty_backordered'   => (float)$childItem->getQtyBackordered()
                );
            }
        }

        $items[] = array(
            'name'              => $orderItem->getName(),
            'qty_backordered'   => $orderItem->getHasChildren() ? $sumBackordered : (float)$orderItem->getQtyBackordered(),
            'children'          => $orderItem->getHasChildren() ? $children : null
        );
    }

    Zend_Debug::dump($items);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.