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!

$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 '14 at 7:57
  • yes you can call – Magento Learner Feb 14 '14 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 '14 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 '16 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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