【问题标题】:Magento Adminhtml Grid using sales/order_item collection filtered by customerMagento Adminhtml Grid 使用按客户过滤的 sales/order_item 集合
【发布时间】:2013-03-18 10:30:02
【问题描述】:

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

【问题讨论】:

  • 这是个好主意,顺便说一句

标签: php magento magento-1.7 adminhtml


【解决方案1】:

我可能错了,但您不能在包含销售订单项目的报价单上设置集合()。它必须填充销售/报价模型项。

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

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

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

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

【讨论】:

    【解决方案2】:

    我们的首席开发人员设法帮助我让它工作起来。我们仍然不确定为什么,但这似乎有效

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      相关资源
      最近更新 更多