Gabriel Spiteri
Gabriel Spiteri

Reputation: 4978

Magento - get children of quote item

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

Answers (3)

Steve Ross
Steve Ross

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

Damon
Damon

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

Vijay Kumar
Vijay Kumar

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

Related Questions