开发者

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($quo开发者_运维知识库teItemId);

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);


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜