Magento - get kids out of quotes

I am trying to get quote elements that have a specific parent_item_id

Actually, I have an instance of the parent element of the quote that I got like this:

$parentQuoteItem = Mage::getModel("sales/quote_item")->load($quoteItemId); 

How can I extract the children of this quote element?

I tried calling the getChildren () method, but unfortunately it gave an empty array:

 $parentQuoteItem->getChildren() 

Any help is appreciated :)

--------------- UPDATE ------------------------ -----

I solved the problem with the following code:

 $aChildQuoteItems = Mage::getModel("sales/quote_item") ->getCollection() ->setQuote($mQuote) ->addFieldToFilter("parent_item_id", $quoteItemId); 
+7
source share
3 answers

You probably need to load the quote first before calling getparent / child on the element ...

 $parent_quote = Mage::getModel("sales/quote")->load($quote_id); $q_item = $quote->getItemById('q_item_id_looking_for')->getChildren(); // do something with them... 
+3
source

I tried above but did not work for me. Here is how I solved it:

 <?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 ?> 

The above is useful if your Bundle product has a fixed price type.

0
source

I do not like this 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 ?> 
-2
source

All Articles