By In Magento

Magento – Dashboard Last 5 Orders are missing Guest Name

The Magento Dashboard is the landing page of Magento administration. From Dashboard you can check site’s activity and performance without the need to open every section. Beside sales related data like lifetime sale, 24hour order activity, there are other interesting things like frequently used search terms within the site and recently viewed products.

One of the interesting sections is ‘Last 5 Orders’ block.
It is a list of a five most recently placed orders in your store. Customer information, items ordered, and the order totals are included. However there is one small issue with this block. All customers that have made order as Guests will not have their names displayed in this block. When you click on blank field it will lead you to Order details page and than you can see customer`s name from Billing/Shipping addresses. It is very annoying if you have a lot of customers that shop as guests and force you to open order page just to see a name of customer.

This issue can be fixed easily with small modification. Since it is really small change we will not create our own module and instead we will overwrite Magento core files. To apply changes propelly we will not edit core files directly, we will copy core files into ‘local’ folder following same path strucutre.

Files that we need to copy are (create all missing folders):
app/code/core/Mage/Reports/Model/Resource/Order/Collection.php
to a folder:
app/code/local/Mage/Reports/Model/Resource/Order/Collection.php

and:
app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php
to a folder:
app/code/local/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php

Open file ‘Collection.php’ and find function ‘joinCustomerName’ and bellow it add new function:
public function joinCustomerBillingName($alias = 'name')
{
$fields = array('t2.firstname', 't2.lastname');
$fieldConcat = $this->getConnection()->getConcatSql($fields, ' ');
$this->getSelect()
->join(array('t2' => 'sales_flat_order_address'),'main_table.billing_address_id = t2.entity_id',array($alias => $fieldConcat));
return $this;
}

Idea is to use Billing information first and last name instead Customer data, that way we will have names displayed for guests too.
After adding function we will call it in file ‘Grid.php’ file, find line:
->joinCustomerName(‘customer’)
and replace it with:
->joinCustomerBillingName(‘customer’)

While we still have ‘Grid.php’ file opened in editor we will add one more column that will show status of an order so you can really see if it is necessary to open order details page. Find function ‘_prepareColumns’ and copy this code wherever you want ‘Order status’ to appear in ‘Last 5 Orders’ block.

$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'sortable' => false,
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));

If for some reason instructions that I provided are not clear enough here is the patch file, all that you need to do is to download and unpack file from this link. After that copy files into your Magento installation root folder, pay attention that there are no files that will be overwritten. Once upload is done login into admin and check Dashboard, guests names should appear same as it was case for regular customers.

Be sure to make backup of your store before applying patch, in case that issue appears you will be able to easily revert changes.

5 Responses to Magento – Dashboard Last 5 Orders are missing Guest Name

  1. ronald says:

    Sorry it doesnt work for 1.9.2.1 I get a security exception

  2. Gaby says:

    Perfect, worked excellent for me. Thank You for giving this good solution.

  3. Tom says:

    Great work. Thank you very much for the patch files, works perfectly!!!

  4. Javier Arias says:

    This script does not work if your Magento tables are prefixed. joinCustomerBillingName() function has to be this way:


    public function joinCustomerBillingName($alias = 'name')
    {
    $sales_table = Mage::getSingleton( 'core/resource' )->getTableName( 'sales_flat_order_address' );
    $fields = array('t2.firstname', 't2.lastname');
    $fieldConcat = $this->getConnection()->getConcatSql($fields, ' ');
    $this->getSelect()
    ->join(array('t2' => $sales_table),'main_table.billing_address_id = t2.entity_id',array($alias => $fieldConcat));
    return $this;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *