0

I try this code to get qty of products from order.

$orderId = 'My Order ID;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$items = $order->getAllVisibleItems();

foreach ($items as $item) {
    $qty[$item->getName()] = $item->getQtyToInvoice();
}

print_r ($qty); 

The above code not work for bundle product, it returns 0.

But for others product type, it works.

  • Hope this will help. stackoverflow.com/questions/8296719/… – Sukeshini Nov 20 '13 at 4:25
  • Thanks for your reply @Su123, I can get bundle product qty from quote with this code $item->getQty(). What I want is get bundle product qty from ordered item. Do you have any solutions?? – Wakanina Nov 20 '13 at 4:43
  • Bundle product can come as fixed price bundles or with dynamic pricing. It pays to check which one you are using and test your final solution with both. – Kristof at Fooman Jan 18 '14 at 23:52
2

Bundle Products

Bundle product quote items are represented by one item for the bundle product and separate simple product items for each option. The simple product items have the quantity information stored against them. The simple items have a parent item ID which refers back to the bundle product quote item, just as configurable product quote items' children items do.

This is also true for the order, as far as I am aware.

If you look at the function getAllVisibleItems it appears to exclude the child elements from the returned items array. So you will only get the parent element which has no quantity.

public function getAllVisibleItems()
{
    $items = array();
    foreach ($this->getItemsCollection() as $item) {
        if (!$item->isDeleted() && !$item->getParentItemId()) {
            $items[] =  $item;
        }
    }
    return $items;
}

I would suggest that to get all the true item's quantity you switch to using getAllItems which does not check against parent item id.

public function getAllItems()
{
    $items = array();
    foreach ($this->getItemsCollection() as $item) {
        if (!$item->isDeleted()) {
            $items[] =  $item;
        }
    }
    return $items;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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