【问题标题】:Magento - get children of quote itemMagento - 获取报价项目的孩子
【发布时间】:2011-06-23 14:20:45
【问题描述】:

我正在尝试检索具有特定 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);

【问题讨论】:

  • 嗯,不知道你到底需要什么。看看$parentQuoteItem->getOptions(),它返回你需要的吗?
  • 不幸的是,它返回了一个空数组:S ...谢谢你的朋友。我以另一种方式解决了这个问题。查看更新的问题
  • 您能否提供您对自己问题的回答作为答案,而不是将其内联在您的问题中?这样就可以投票了。

标签: magento


【解决方案1】:

您可能需要先加载报价,然后再对项目调用 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...

【讨论】:

    【解决方案2】:

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

    <?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 产品是固定价格类型,上述内容会很有帮助。

    【讨论】:

      【解决方案3】:

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

      ?php foreach(Mage::getSingleton('checkout/session')->getQuote()->getAllItems() as $_item): ?>
      
                  <?php
                      if ($item->getHasChildren()){
      
                          $qty = $_item->getQty();
                      }
                  ?>
                  <?php endforeach ?>
      

      【讨论】:

      • 你能解释一下为什么你的答案更好吗?
      • @KatieK 他的回答更好,因为他没有加载新的报价项目,这意味着对数据库的压力更小。
      • 这根本没有回答问题。它的模板语法也很糟糕。
      猜你喜欢
      • 2013-08-13
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多