I want to show customer having specific value for attribute. Suppose I made customer attribute say refcode, now I want to get list of all customer having refcode 1.
How can I add filter to list of customer?
If refcode
is customer eav
then you can filter this by function addAttributeFilter('attributecode','fiterablevalue')
1St: Need to load customer collection
$collection = Mage::getResourceModel('customer/customer_collection');
2nd: then filter by addAttributeToFilter()
$collection->addAttributeToFilter('refcode',1)
3rd: foreach
loop to get get list of all customer having refcode 1.
For add an eav attribute
to collection you need to use the function addAttributeToSelect('attribute_code')
add
Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('refcode');
For getting all field use ->addAttributeToSelect('*')
function which is include all eav attribute
to collection
Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('*');
If you want a collection to array
then use below function ->__toArray ()
or ->toArray()
That means to get array of collection use below as exmpale
$collection->toArray();
You can get collection of customer through :
$collection = Mage::getModel('customer/customer')->getCollection();
Filter you collection according to attribute :
$collection->addAttributeToFilter('refcode', array('eq' => 1));
You can easily add the attribute to the grid, using:
https://github.com/magento-hackathon/GridControl
Then you can filter the grid by the attribute