Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: get all customer from a group

Tags:

php

magento

Like said on title, i need to get all the users assigned to a specific group.

In magento, i've created a customer group named "customers" with ID 4.

Now i need to list all the users in this group outside magento with a custom script, and i can't find a solution.

with this little code i can get ALL registered users, do you know how i can filter this to get only customers in group ID 4?

    $collection = Mage::getModel('customer/customer')
        ->getCollection()
        ->addAttributeToSelect('*');
    $result = array();
    foreach ($collection as $customer) {
        $result[] = $customer->toArray();
    }

Thank you!

like image 890
Laphroaig Avatar asked Nov 30 '22 13:11

Laphroaig


2 Answers

You can easily add a filter to the collection to return all customers from a specific group.

$collection = Mage::getModel('customer/customer')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->addFieldToFilter('group_id', 4);
like image 186
1000Nettles Avatar answered Dec 05 '22 19:12

1000Nettles


I think you should add: ->addFieldToFilter('customer_group_id','1');

like image 23
jmmeijer Avatar answered Dec 05 '22 19:12

jmmeijer