Magento. Add to newsletter subscribers grid customer group column with sort and filter.
If you need add to newsletter subscribers grid the customer group (NOT LOGGEED, General, Wholesale, Retail etc) and want use this comlumn for sort, filter I have one solution to how to do it.
The main point why I rewrote the model, block and did not use the Observer is used for unregistered subscribers NOT_LOGGED group and the ability to filter and sort by it, now describe in more detail.
As we know we can get from main tabel with JOIN LEFT from customer_entity table customer group and values wiil be for standart General = 1, Wholesale = 2 and Retail = 3 but for unregistered user it will NULL and we can’t user sort and filter by this column. For solve this I rewrote method showCustomerInfo() of Mage_Newsletter_Model_Resource_Subscriber_Collection class to add:
Pay attention to this point
I’m replace NULL value for customer group id and customer id to 0 for use it in my custom filter method.
Full method code:
Than I rewrote method _prepareColumns() of class Mage_Adminhtml_Block_Newsletter_Subscriber_Grid for add new colunm:
and add custom filter method namely _customerGroupFilter()