Magento - 获取报价项目的子项

时间:2011-06-23 14:20:46

标签: magento

我正在尝试检索具有特定parent_item_id

的引用项

我实际上有一个我引用的父引用项的实例:

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

如何提取此报价项的子项?

我试过调用getChildren()方法但不幸的是它给出了一个空数组:

$parentQuoteItem->getChildren()

非常感谢任何帮助:)

---------------的更新 ------------------------ -----

我有点用以下代码解决了这个问题:

$aChildQuoteItems = Mage::getModel("sales/quote_item")
                                ->getCollection()
                                ->setQuote($mQuote)
                                ->addFieldToFilter("parent_item_id", $quoteItemId);

3 个答案:

答案 0 :(得分:3)

您可能需要先在项目上调用getparent / child之前加载引号...

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

答案 1 :(得分:0)

我上面试过,但对我不起作用。以下是我解决这个问题的方法:

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

如果您的Bundle产品是固定价格类型,则上述内容非常有用。

答案 2 :(得分:-2)

不喜欢你有太多的解决方案,为什么不:

?php foreach(Mage::getSingleton('checkout/session')->getQuote()->getAllItems() as $_item): ?>

            <?php
                if ($item->getHasChildren()){

                    $qty = $_item->getQty();
                }
            ?>
            <?php endforeach ?>
相关问题