Pregunta

Here is my collection below.I tried to rewrite the sales order grid with adding another column as email .The column came but the result for the column email is not displaying in my custom grid.
On checking with collection->getData(); I am getting 'customer_email" but it's not populating in grid.

  protected function _prepareCollection() {

            $collection = Mage::getResourceModel($this->_getCollectionClass());

     $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('customer_email' => 'customer_email'));
    }
$this->setCollection($collection);
        //print_r($collection->getData());exit;
        return parent::_prepareCollection();

    }

and adding column is here

$this->addColumn('customer_email', array(
        'header'=> Mage::helper('sales')->__('Email'),
        'type'  => 'text',
        'index' => 'customer_email',
        'align'    => 'customer_email',
  'filter_index' => 'sales_flat_order.customer_email',
        ));

Anyone who have faced this scenario earlier please guide me to get my self out,thanks in advance.

¿Fue útil?

Solución

Your code is correct, the only thing you are doing wrong here is you are returning return parent::_prepareCollection(); which returns parent collection data. You only have to remove that line to make your code work.

You can use it as below.

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('customer_email' => 'sales_flat_order.customer_email'));
    $this->setCollection($collection);
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top