I have been creating one custom module for block some customer group to wholesale store. we can get customer group id by current session like

$session = Mage::getSingleton('customer/session');

 // Get the Customer Group ID.

$group_id = $session->getCustomerGroupId();

But i want to block those customers before login. How to get customer group id by $login['username'] before setting session? Anybody have an idea? Please help me guys!

2 Answers 2

$customer = Mage::getModel("customer/customer");
$customer->loadByEmail($customer_email); //load customer by email id
echo $customer->getGroupId(); 
  • can we call "Mage::getModel("customer/customer");" in controller file?
    – DRAJI
    Feb 14, 2014 at 7:57
  • yes you can call Feb 14, 2014 at 7:57
  • 1
    yes. great! its working. Thank you so much yar! but small change,$customer->getCustomerGroupId(); it returns empty value. $customer->getGroupId(); -This is correct syntax. Please edit answer
    – DRAJI
    Feb 14, 2014 at 8:03
$collection = Mage::getModel('customer/customer')

$result = array();

foreach ($collection as $customer) {
    $result[] = $customer->toArray();

Now $result having information of all customer in your store.

  • This is a pretty bad advice. $collection (once loaded) already contains all this information. Looping over it and putting it in an array has no actual use and is only doubling the amount of memory used to hold the data.
    – 7ochem
    Jun 29, 2016 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.