0

how can i add customer email in admin html grid magento. i get customer email in collection but not displayed in column of Customer Email. Please Help me.

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->join('order', 'main_table.entity_id = order.entity_id', 'customer_email');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
protected function _prepareColumns()
{
        $this->addColumn('customer_email', array(
        'header' => $this->helper('sales')->__('Customer Email'),
        'index' => 'customer_email',
    ));
}
4
protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft(
        array('myorder'=>'sales_flat_order'),
        'myorder.entity_id = main_table.entity_id',
        array('myorder.customer_email')
    );
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

You need to add filter_index to code

$this->addColumn('customer_email', array(
    'header' => $this->helper('sales')->__('Customer Email'),
    'index' => 'customer_email',
    'filter_index' => 'myorder.customer_email',
));
  • Excellent. Just for others who are looking to do this, I had edited app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php - I'm not sure if this is the correct file, but it worked for me. – Half Crazed Nov 24 '15 at 15:15
  • Actually, quick update, this will break your searches due to "ambiguous" rows being called... which means you will need to add the "filter_index" to each of your addColumn methods, using the "main_table.column_name" format. – Half Crazed Nov 24 '15 at 19:09
1

In Grid.php:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()
        ->join(
            'customer_entity',
            'main_table.customer_id = customer_entity.entity_id', array('customer_name' => 'email')
        );
    $this->setCollection($collection);

    return parent::_prepareCollection();
}

Then in protected function _prepareColumns() function add following code:

$this->addColumn('thumbnail', array(
    'header'    => Mage::helper('Sales')->__('Email'),
    'width'     => '100px',
    'index'     => 'customer_name',
    'type'        => 'text',
));

I think this link will solve your problem if you want to do more.

I know it was better to share the code, but the code is too much that's why I preferred to share the Link.

  • i get data when i update _prepareCollection like protected function _prepareCollection() { parent::_prepareCollection(); $collection = Mage::getResourceModel($this->_getCollectionClass()); $this->setCollection($collection); $collection->join('order', 'main_table.entity_id = order.entity_id', 'customer_email'); return true; } but search functionality is not working of whole grid. – Jaydeep Jun 7 '14 at 8:01
  • Try the way i shared – TBI Infotech Jun 7 '14 at 8:05
  • i want to add customer email column in grid and sorting ,filtering should be work properly. – Jaydeep Jun 7 '14 at 8:07
  • The way i shared it is working, please share if there is any issue with the code i shared. – TBI Infotech Jun 7 '14 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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