I want to display the total of order for each customer, in the customer grid (Back Office).
Currently, I succeed to display the total, only if there is at least 1 order.
In _prepareCollection() :
$readAdapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $readAdapter->select()
->from('sales_flat_order_grid')
->columns(array('orders_count' => new Zend_Db_Expr('COUNT(*)'))
)->group('customer_id');
$collection->getSelect()->joinLeft(
array('orders_count' => new Zend_Db_Expr('('.$select.')')),
'e.entity_id = orders_count.customer_id',
array('orders_count.orders_count')
);
$collection->addFilterToMap('orders_count', 'orders_count.orders_count');
$this->setCollection($collection);
In _prepareColumns(), I added the custom column :
$this->addColumn('orders_count', array(
'header' => Mage::helper('customer')->__('Total nb of orders'),
'width' => '40px',
'index' => 'orders_count',
'type' => 'number',
'sortable' => false,
'filter_condition_callback' => array($this, '_ordersCountFilterCallBack')
));
I can force the displaying of 0 by add 'default' => '0' in my column but it's not that I want : In my _ordersCountFilterCallBack function, I want to be allow to filter orders_count.orders_count == 0 and not orders_count.orders_count IS NULL.
Any idea ?
_ordersCountFilterCallBack
function?