0

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!

0

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

  • it shows an empty field. it's not working :( – daniel Feb 27 at 11:43
  • Not sure why, check screenshot – Sohel Rana Feb 27 at 11:48
  • can you point the path of the right config.xml? i think i have a problem there. – daniel Feb 27 at 12:08
  • Check updated answer – Sohel Rana Feb 27 at 13:01
  • not working, image here link – daniel Feb 27 at 13:20

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.