user3284959
user3284959

Reputation: 9

Magento add company name to order and customer grid

What I need is to show Company name instead of first and lastname whenever customer address is shown.

Besides that, I need to add company name to registration form, customer and order grid.

What is the best way(s) to achieve this?

Upvotes: 0

Views: 1857

Answers (1)

JohnyFree
JohnyFree

Reputation: 1369

I was adding this today into some Magento store and saw this old question, maybe my answer will help somebody else. This will answer you only how to add company name into order grid. To do that you need to extend Mage_Adminhtml_Block_Sales_Order_Grid class. Then you override _prepareCollection and _prepareColumns functions. This code is based on this free extension

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $tableName = Mage::getSingleton("core/resource")->getTableName('sales_flat_order_address');                  
    $collection->getSelect()->join($tableName, "main_table.entity_id = $tableName.parent_id AND $tableName.address_type='billing'",array('company'));
    $this->setCollection($collection);               
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
} 

protected function _prepareColumns()
{
    $this->addColumnAfter('company', array(
        'header'    => Mage::helper('customer')->__('Company'),
        'index'     => 'company'
    ),'billing_name');   

    return parent::_prepareColumns();
}

Upvotes: 1

Related Questions