I want to add news letter subscribed or not as column. but I dont have idea from which table i have to join. can you any one help me on this?

class Gumbrands_Customergrid_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid{
     * override the _prepareCollection to add an other attribute to the grid
     * @return $this
    protected function _prepareCollection(){
        $collection = Mage::getResourceModel('customer/customer_collection')
            //if the attribute belongs to the customer, use the line below
            //if the attribute belongs to the customer address, comment the line above and use the one below
            //->joinAttribute('mobile', 'customer_address/mobile', 'default_billing', null, 'left')
            ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
            ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
            ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
            ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
            ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

        //code from Mage_Adminhtml_Block_Widget_Grid::_prepareCollection()
        //since calling parent::_prepareCollection will render the code above useless
        //and you cannot call in php parent::parent::_prepareCollection()
        if ($this->getCollection()) {


            $columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort);
            $dir      = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
            $filter   = $this->getParam($this->getVarNameFilter(), null);

            if (is_null($filter)) {
                $filter = $this->_defaultFilter;

            if (is_string($filter)) {
                $data = $this->helper('adminhtml')->prepareFilterString($filter);
            else if ($filter && is_array($filter)) {
            else if(0 !== sizeof($this->_defaultFilter)) {

            if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) {
                $dir = (strtolower($dir)=='desc') ? 'desc' : 'asc';

            if (!$this->_isExport) {

        return $this;

     * override the _prepareColumns method to add a new column after the 'email' column
     * if you want the new column on a different position just change the 3rd parameter
     * of the addColumnAfter method to the id of your desired column
    protected function _prepareColumns(){
        $this->addColumnAfter('news_letter', array(
            'header'    => Mage::helper('customer')->__('Mobile'),
            'index'     => 'mobile'
        return parent::_prepareColumns();
 * Preparing customer collection
public function setCollection($collection)

 * Adding columns to customer grid
protected function _prepareColumns()


    $this->addColumnAfter('newsletter_subscribed', array(
        'header' => Mage::helper('sales')->__('Newsletter Subscribed'),
        'index' => 'origin',
        'type' => 'text',
        'width' => '100px',
            ), 'entity_id');
    return parent::_prepareColumns();

you can join newsletter_subscriber

| improve this answer | |
  • can u give syntax for joinnewsletter_subscriber table – sivakumar Jun 9 '15 at 13:57

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.