在magento的Grid中经常会出现_prepareCollection方法中的数据是下面这样筛选添加字段进去的:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('sales/order_grid_collection')
->addFieldToSelect('entity_id')
->addFieldToSelect('increment_id')
->addFieldToSelect('customer_id')
->addFieldToFilter('customer_id', Mage::registry('current_customer')->getId())
->setIsCustomerMode(true);
$this->setCollection($collection);
return parent::_prepareCollection();
}
如果想重写这个方法像平时那样重写是没办法写入的,所以应该讲重写的方法写成是一个新的方法,这样就可以看作是父类调用此方法了,而不是去重写_prepareCollection方法,所以应该如下:
public function setCollection($collection)
{
$collection->addFieldToSelect('status');
$this->_collection = $collection;
}