Magento - 重新编写管理销售订单网格以从数据库字段添加自定义列
Magento - re write admin sales order grid to add custom column from DB field
我正在尝试扩展 Mage_Adminhtml_Block_Sales_Order_Grid
以添加新列。
我希望在网格中显示的“sales_flat_order
”table (order_ready_for_dispatch
) 中有一个填充字段(此字段单独为 added/updated)。
问题是数据未显示在具有以下代码的该列中:
/app/code/local/Sulman/SalesGrid/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<modules>
<Sulman_SalesGrid>
<version>1.0.0</version>
</Sulman_SalesGrid>
</modules>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
app/code/local/Sulman/SalesGrid/Block/Adminhtml/Sales/Order/Grid.php
<?php
class Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareCollection() {
$collection = parent::_prepareCollection()->getCollection();
$collection->addFieldToSelect('order_ready_for_dispatch');
return $this;
}
protected function _prepareColumns()
{
$this->addColumn('order_ready_for_dispatch', array(
'header'=> Mage::helper('sales')->__('Despatch Date'),
'width' => '80px',
'type' => 'text',
'index' => 'order_ready_for_dispatch',
));
return parent::_prepareColumns();
}
}
谁能看出我的错误?谢谢 :)
好的,所以我通过改变我的 _prepareCollection()
方法让它工作:
protected function _prepareCollection(){
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id', array('order_ready_for_dispatch'));
$this->setCollection($collection);
return $this;
}
我正在尝试扩展 Mage_Adminhtml_Block_Sales_Order_Grid
以添加新列。
我希望在网格中显示的“sales_flat_order
”table (order_ready_for_dispatch
) 中有一个填充字段(此字段单独为 added/updated)。
问题是数据未显示在具有以下代码的该列中:
/app/code/local/Sulman/SalesGrid/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<modules>
<Sulman_SalesGrid>
<version>1.0.0</version>
</Sulman_SalesGrid>
</modules>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
app/code/local/Sulman/SalesGrid/Block/Adminhtml/Sales/Order/Grid.php
<?php
class Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareCollection() {
$collection = parent::_prepareCollection()->getCollection();
$collection->addFieldToSelect('order_ready_for_dispatch');
return $this;
}
protected function _prepareColumns()
{
$this->addColumn('order_ready_for_dispatch', array(
'header'=> Mage::helper('sales')->__('Despatch Date'),
'width' => '80px',
'type' => 'text',
'index' => 'order_ready_for_dispatch',
));
return parent::_prepareColumns();
}
}
谁能看出我的错误?谢谢 :)
好的,所以我通过改变我的 _prepareCollection()
方法让它工作:
protected function _prepareCollection(){
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id', array('order_ready_for_dispatch'));
$this->setCollection($collection);
return $this;
}