What I would like to achieve is to show Account Name + Lastname in sales order grid (like it happens in customer grid).

These are files I created:




class Cpu_CustomGrid_Model_Observer extends Varien_Event_Observer
public function addColumnsToSalesOrderGrid(Varien_Event_Observer $observer)
    $event = $observer->getEvent();
    $this->_grid = $event->getBlock();
    if ($this->_grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
        $this->_collection = $this->_grid->getCollection();

        $select = $this->_collection->getSelect();
        $resource = Mage::getSingleton('core/resource');    

        $columnData = array(
                'header' => 'Name',
                'index'  => 'name', // Account Name/Surname
                'type' => 'text',
                'renderer' => 'Cpu_CustomGrid_Block_Getname' 

        $this->_grid->addColumnAfter('name', $columnData, 'company');

        // rebuild the filters
        $filter = $this->_grid->getParam($this->_grid->getVarNameFilter(), null);
        if (is_null($filter)) {
        if (is_string($filter)) {
            $data = $this->_grid->helper('adminhtml')->prepareFilterString($filter);
        } else {
            if ($filter && is_array($filter)) {
        // force a reload of the collection



class Cpu_CustomGrid_Block_Getname extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
    public function render(Varien_Object $row)
         return $row->getFirstname().' '.$row->getLastname();

Unfortunately I cannot get the Name + Lastname to show. What could be the problem?

  • Please make print_r to $row and check what all results you are getting
    – Nihar S
    Apr 24, 2017 at 16:28

1 Answer 1


I guess the problem is that you do not have the "firstname" and "lastname" datas in your collection. You will have to make one or two sql join in order to get it. Unfortunatly, it does not appear to be easy because these data are customer eav attributes.

As your collection is a Mage_Sales_Model_Resource_Order_Collection object, you can take a look to the app/code/core/Mage/Sales/Model/Resource/Order/Collection.php::_addAddressFields method in you want a more precise idea of what I mean (this method joins the collection with the table 'sales/order_address' to get Firstname and Lastname of the order addresses).

I did not test it but you should try to join with the 'customer_entity_varchar' table with something like :

$firstnameAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'firstname');
                $firstnameTable = $firstnameAttribute->getBackendTable();
                $firstnameId = $firstnameAttribute->getAttributeId();

            array('cevfirst' => $firstnameTable),
            'main_table.customer_id = cevfirst.entity_id AND cevfirst.attribute_id ='.$firstnameId,
                        'customer_firstname' => new Zend_Db_Expr('cevfirst.value'),

You should then be able to get the firstname data with


After that, you should repeat the same thing to get the lastname value.

I hope this will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.