1

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.

1 Answer 1

1

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();
}
2
  • it worked however the filter is not working for the same, any suggestion @jaimin Apr 18, 2017 at 11:03
  • Please Try with above code Apr 18, 2017 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.