Search This Blog

Tuesday 4 September 2012

Get all customer groups in Magento

$customer_group = new Mage_Customer_Model_Group();
$allGroups  = $customer_group->getCollection()->toOptionHash();
foreach($allGroups as $key=>$allGroup){
   $customerGroup[$key]=array('value'=>$allGroup,'label'=>$allGroup);
}
return $customerGroup;

3 comments:

  1. What if i want to set 'value'=> to be this groups ID. Can you show an examle, how to do that? Thanks.

    ReplyDelete
  2. Never *ever* use "new" to instantiate models, that's just very bad practise.
    Here is a much cleaner solution : Mage::getResourceModel('customer/group_collection')->toOptionHash();

    ReplyDelete
  3. This is a great post. I like this topic.This site has lots of advantage. It helps me in many ways.Thanks for posting this again.
    magento development company in bangalore 

    ReplyDelete