Question

I want to add a column in Manage Customers Grid

app/code/core/Mage/Adminhtml/Block/Customer/Grid.php

with the VAT Number of customers.

Now i have ID, Name, Email, Telephone, Country etc.

I need to add the attribute in prepare collection and the column in prepare columns.

Help please!

Was it helpful?

Solution

Try the following way:

Add the following code in config.xml which is related to overwrite grid

app/code/local/SR/MagentoCommunity/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <SR_MagentoCommunity>
            <version>0.0.0.1</version>
        </SR_MagentoCommunity>
    </modules>
    <global>
        <models>
            <sr_magentocommunity>
                <class>SR_MagentoCommunity_Model</class>
            </sr_magentocommunity>
        </models>
        <blocks>
            <sr_magentocommunity>
                <class>SR_MagentoCommunity_Block</class>
            </sr_magentocommunity>
            <adminhtml>
                <rewrite>
                    <customer_grid>SR_MagentoCommunity_Block_Adminhtml_Customer_Grid</customer_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

And

app/code/local/SR/MagentoCommunity/Block/Adminhtml/Customer/Grid.php

<?php

class SR_MagentoCommunity_Block_Adminhtml_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
    /**
     * @param Mage_Customer_Model_Resource_Customer_Collection $collection
     */
    public function setCollection($collection)
    {
        $collection->addAttributeToSelect('taxvat');
        parent::setCollection($collection);
    }

    protected function _prepareColumns()
    {
        parent::_prepareColumns();

        $this->addColumnAfter('taxvat', array(
            'header'    => Mage::helper('customer')->__('VAT Number'),
            'index'     => 'taxvat'
        ), 'customer_since');

        $this->sortColumnsByOrder();
        return $this;
    }
}

app/etc/modules/SR_MagentoCommunity.xml

<?xml version="1.0"?>
<config>
    <modules>
        <SR_MagentoCommunity>
            <active>true</active>
            <codePool>local</codePool>
        </SR_MagentoCommunity>
    </modules>
</config>

Grid Detail Page From where comes Vat

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top