Magento Adminhtml Grid使用按客户筛选的sales / order_item集合

时间:2013-03-18 10:30:02

标签: php magento magento-1.7 adminhtml

我的目标很简单。我有一个名为Quotes的模块,我已经设法让Magento在每次创建购物车时创建一个新的报价记录,方法是在“检出”报价时更改is_active列。所以我有一堆报价,每个报价都与客户有关,我有sales / order_item行,每行与报价相关。 我在后端有一个页面,显示所有引号的网格。单击引号时,编辑页面有两个选项卡,一个带有Form.php,显示引用的详细信息。 (客户名称,日期等),然后我有另一个选项卡,其中应包含该引用中所有项目的网格。看起来很简单:

$this->addTab("items_section", array(
  "label" => Mage::helper("quote")->__("Quote Items"),
  "title" => Mage::helper("quote")->__("Quote Items"),
  "content" => $this->getLayout()->createBlock("quote/adminhtml_quotes_edit_tab_cart")->toHtml(),
));

然后在我的购物车块中我有这个:

protected function _prepareCollection()
{
    $collection = Mage::getModel('sales/order_item')->getCollection();
    print_r($collection);
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

我甚至不想加载正确的集合(通过order_id),因为这里首先要解决一个问题:print_r语句显示我指定的集合,但将其传递给$ this-> setCollection($ collection)让我在网格中呈现'找不到记录'。在典型的Magento方式中没有错误等。我理解该模型应该根据需要查询数据库,但似乎并没有发生。我想是时候阅读Mage :: core文件,但是你可以想象我对如此简单的任务感到非常沮丧,所以如果有人知道这里发生的事情可以帮助我,我会很感激。提前谢谢。

2 个答案:

答案 0 :(得分:0)

我可能错了,但您不能在带有销售订单商品的报价上设置.Collection()。它必须填充销售/报价模型项目。

我不知道$ this在_prepareCollection()中的范围是什么,但我假设它在购物车块上,它处理报价。

只是提示,你可能而不是print_r($ collection),尝试这样做......

echo "<pre>";
foreach ($collection as $item) {
    var_dump($item->debug());
}

它几乎只提供重要信息而不是数据库结构。您还可以检查项目类型,并确保使用setCollection方法的正确模型。你也可以休息一下;在那里如果你想获得第一个项目等。调试magento对象可能很乏味,我发现这有帮助。

答案 1 :(得分:0)

我们的首席开发人员成功帮助我实现了目标。我们仍然不确定为什么,但这似乎有效

 protected function _prepareCollection()
{
    $quoteId = $this->getRequest()->getParam('id');

    $quote = Mage::getModel('sales/quote')->getCollection()->addFieldToFilter('entity_id', $quoteId);
    if ($quote->getFirstItem()->getId()) {
        $collection = $quote->getFirstItem()->getItemsCollection(false);
    }
$this->setCollection($collection);

    return parent::_prepareCollection();
}
相关问题