i want to show number of orders in customer grid of magento
i used this as a guide: How to add customer "total number of orders" and "total spent" to order grid in magento 1.7
but this is a different grid
so far i have created: app/code/local/Mage/Adminhtml/Block/Customer/Grid.php
_prepareCollection
i added:
$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)')
);
$collection->groupByAttribute('entity_id');
before: $this->setCollection($collection);
_prepareColumns i added:
$this->addColumn('order_count', array(
'header' => Mage::helper('customer')->__('# orders'),
'index' => 'order_count',
'type' => 'number'
));
while it does work in the grid, i have some problems:
the pager shows 1 customer (should be 500+)
sorting on this new column doesn't work