I'm trying to add some extra columns into Magento's customer grid.
I've got an order count working successfully (Total amount of orders a customer has placed)
I'm trying to get the Last Order date in, but I'm unable to get it working.
Has anyone done this before or can someone point me in the right direction as to how to do this?
This is my current code, but it errors and just displays a SQL query.
$orderTableName = Mage::getSingleton('core/resource')
->getTableName('sales/order');
$collection->getSelect()
->joinLeft(
array('orders' => $orderTableName),
'orders.customer_id=e.entity_id',
array(
'order_count' => 'COUNT(customer_id)',
'last_order' => 'MAX(created_at)'
)
);
$collection->groupByAttribute('entity_id');
Best Answer
Here is working example for CE 1.8.1:
and
The output is