Skip to main content
Tweeted twitter.com/StackMagento/status/1061317664180723713
edited tags
Link
Fabian Schmengler
  • 66.1k
  • 25
  • 188
  • 422
added 1029 characters in body
Source Link

I have added total number of orders column to customer grid in the magento admin. I need to put 2 text box in that column like from and to so we can search customers whose total orders are between that given range.

ex. suppose we put 3 and 5 into (form and to) textbox then we will display all customers whose total orders are between 3 to 5.

and also need to work filtering (searching and sorting)

add code in the following file app\code\core\Mage\Adminhtml\Block\Customer\Grid.php

add this code in _prepareCollection() fucntion only

$sql ='SELECT COUNT(*)'
        . ' FROM ' . Mage::getSingleton('core/resource')->getTableName('sales/order') . ' AS o'
        . ' WHERE o.customer_id = e.entity_id ';
        $expr = new Zend_Db_Expr('(' . $sql . ')'); 

        $collection->getSelect()->from(null, array('orders_count'=>$expr));

and also need to work filtering add this code in _prepareColumns(searching and sorting) function with same file

$this->addColumn('orders_count', array(
            'header'    => Mage::helper('customer')->__('Total Orders'),
            'align'     => 'left',
            'width'     => '40px',
            'index'     => 'orders_count',
            'type'  => 'number',
            'sortable' => true,
        ));

I have added total number of orders column to customer grid in the magento admin. I need to put 2 text box in that column like from and to so we can search customers whose total orders are between that given range.

ex. suppose we put 3 and 5 into (form and to) textbox then we will display all customers whose total orders are between 3 to 5.

and also need to work filtering (searching and sorting)

I have added total number of orders column to customer grid in the magento admin. I need to put 2 text box in that column like from and to so we can search customers whose total orders are between that given range.

ex. suppose we put 3 and 5 into (form and to) textbox then we will display all customers whose total orders are between 3 to 5.

and also need to work filtering (searching and sorting)

add code in the following file app\code\core\Mage\Adminhtml\Block\Customer\Grid.php

add this code in _prepareCollection() fucntion only

$sql ='SELECT COUNT(*)'
        . ' FROM ' . Mage::getSingleton('core/resource')->getTableName('sales/order') . ' AS o'
        . ' WHERE o.customer_id = e.entity_id ';
        $expr = new Zend_Db_Expr('(' . $sql . ')'); 

        $collection->getSelect()->from(null, array('orders_count'=>$expr));

and also add this code in _prepareColumns() function with same file

$this->addColumn('orders_count', array(
            'header'    => Mage::helper('customer')->__('Total Orders'),
            'align'     => 'left',
            'width'     => '40px',
            'index'     => 'orders_count',
            'type'  => 'number',
            'sortable' => true,
        ));
edited title
Link

Column How to add column for total orders in customer grid in magento?

added 59 characters in body
Source Link
Loading
added 6 characters in body
Source Link
Loading
format and tag
Source Link
David Manners
  • 27.3k
  • 9
  • 76
  • 220
Loading
Source Link
Loading