Reputation: 4978
I am attempting to retrieve the quote items that have a particular parent_item_id
I actually have an instance of the parent quote item which I retrieved like so:
$parentQuoteItem = Mage::getModel("sales/quote_item")->load($quoteItemId);
How can I extract the children of this quote item?
I have tried calling the getChildren() method but unfortunately its giving an empty array:
$parentQuoteItem->getChildren()
Any help is greatly appreciated :)
---------------UPDATE-----------------------------
I kinda solved the issue with the following code:
$aChildQuoteItems = Mage::getModel("sales/quote_item")
->getCollection()
->setQuote($mQuote)
->addFieldToFilter("parent_item_id", $quoteItemId);
Upvotes: 7
Views: 16784
Reputation: 1218
You probably need to load the quote first before calling getparent/child on the item...
$parent_quote = Mage::getModel("sales/quote")->load($quote_id);
$q_item = $quote->getItemById('q_item_id_looking_for')->getChildren();
// do something with them...
Upvotes: 3
Reputation: 1
not Loving that solution you have too much, why not:
?php foreach(Mage::getSingleton('checkout/session')->getQuote()->getAllItems() as $_item): ?>
<?php
if ($item->getHasChildren()){
$qty = $_item->getQty();
}
?>
<?php endforeach ?>
Upvotes: -2
Reputation: 21
I tried above but didn't work for me. Here is how I resolved this:
<?php foreach(Mage::getSingleton('checkout/session')->getQuote()->getAllItems() as $_item): ?>
<?php
if($_item->getParentItemId()) {
$parentQuote = Mage::getModel("sales/quote_item")->load($_item->getParentItemId());
$qty = $parentQuote->getQty();
} else {
$qty = $_item->getQty();
}
?>
<?php endforeach ?>
Above is helpful if your Bundle product is of fixed price type.
Upvotes: 0