Company Name Column for Order Grid

Company Name Column for Order Grid

October 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Company Name Column for Order Grid

Displaying Both Bill To and Ship To Company Names on Magento Order Grid

Introduction

In this post, we’ll guide you through displaying both the bill to company name and ship to company name on your Magento order grid. This is particularly useful for businesses that often make purchases on behalf of other companies.

The Current Situation

You’ve already managed to display the bill to company name in your order grid by following these steps:

  1. Copied /core/Mage/Adminhtml/Block/Sales/Order/Grid.php to /local/Mage/Adminhtml/Block/Sales/Order/Grid.php.
  2. Updated the _prepareCollection() method to join the required tables and fetch the billing company.
  3. Added a new column ‘company’ under _prepareColumns().

The code you’ve used so far is:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->getCollectionClass());
    $collection->getSelect()->join(
        array('addressTable' => 'sales_flat_order_address'),
        'main_table.entity_id = addressTable.parent_id AND addressTable.address_type = "billing"',
        array('billing_company'=>'company'));
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

And for the column:

$this->addColumn('company', array(
    'header' => Mage::helper('sales')->__('Bill to Company'),
    'index' => 'billing_company',
));

The Challenge: Adding Ship To Company Column

You’ve tried adding a second column for ship to company, but you’re facing two main issues:

  1. Incorrect Position: The new column isn’t appearing where you’ve placed it.
  2. Conflict with Bill to Company Column: If both columns are active, only one has data while the other is empty.

Our Approach

We’ll need to fetch shipping information separately because it’s located on a different row in the database compared to billing information. Let’s modify your _prepareCollection() method:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->getCollectionClass());
    // Fetches bill to company
    $collection->getSelect()->joinLeft(
        array('billingAddress' => 'sales_flat_order_address'),
        'main_table.entity_id = billingAddress.parent_id AND billingAddress.address_type = "billing"',
        array('billing_company'=>'company')
    );
    // Fetches ship to company
    $collection->getSelect()->joinLeft(
        array('shippingAddress' => 'sales_flat_order_address'),
        'main_table.entity_id = shippingAddress.parent_id AND shippingAddress.address_type = "shipping"',
        array('shipping_company'=>'company')
    );

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Notice we’re using joinLeft instead of join. This ensures that if there’s no shipping information, it won’t affect the billing data.

Updating _prepareColumns()

Let’s update your _prepareColumns() to include both company columns:

$this->addColumn('billing_company', array(
    'header' => Mage::helper('sales')->__('Bill To Company'),
    'index' => 'billing.company',
));

$this->addColumn('shipping_company', array(
    'header' => Mage::helper('sales')->__('Ship To Company'),
    'index' => 'shipping.company',
));

Remember to replace billing and shipping with the actual aliases you used in _prepareCollection().

Conclusion

Displaying both bill to company name and ship to company name on your Magento order grid involves a bit of database manipulation. By joining the necessary tables separately and using distinct aliases, we can fetch and display this information without conflicts.

Remember to clear your cache after making these changes for them to take effect.

If you found this guide helpful, feel free to explore our Laravel Company Blog for more Magento tutorials and best practices.

Database Admin Orders

Our network