我的目标很简单。我有一个名为 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 文件了,但你可以想象我对如此简单的任务如此复杂的挫败感,所以如果有人知道这里发生了什么可以帮助我,我将不胜感激。提前致谢。