【问题标题】:Add and show new column in sales_flat_order and show this at order grid in magento在 sales_flat_order 添加并显示新列,并在 magento 的订单网格中显示
【发布时间】:2014-05-14 06:46:06
【问题描述】:

我在 sales_flat_order 中添加了一个新列(已导出)并在此位置添加 at 文件:

app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

protected function _prepareCollection()
{
 $collection = Mage::getResourceModel($this->_getCollectionClass())
    ->addAttributeToSelect('*')
    ->joinAttribute('exported','sales/order','sales_flat_order.entity_id',null,'left');
}

protected function _prepareColumns()
{
 $this->addColumn('exported', array(
            'header' => Mage::helper('sales')->__('Exported'),
            'index' => 'exported',
            'type'  => 'checkbox',
            'name'  =>'exported',
            'value'    =>$this->getExported()==1 ? 'true' : 'false',
          ));
  }

之后它显示在管理站点的订单网格上,但它没有显示价值和名称,

我是magento的新手,所以请帮助我, 从 2 天开始卡住。 感谢您的帮助。

【问题讨论】:

    标签: magento


    【解决方案1】:

    _prepareCollection() 方法使用 sales_flat_order_grid 表作为源,因此您必须将该列添加到 sales_flat_order_grid 表并从 sales_flat_order 表的相应列更新该列的值。

    在这种情况下,Magento 将自动更新 sales_flat_order_grid 表中的这一列以供未来订单使用。

    显示布尔列的更好方法是是/否渲染器。在 _prepareColumns() 方法中使用以下代码

     $this->addColumn('exported', array(
                'header' => Mage::helper('sales')->__('Exported'),
                'index' => 'exported',
                'type'  => 'options',
                'width' => '70px',
                'options' => array(
                    1  => Mage::helper('sales')->__('Yes'),
                    0  => Mage::helper('sales')->__('No'),
                ),
            ));
    

    还有其他一些关于自定义订单网格的有用文章。查看以下链接:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多