MAGENTO – GET CUSTOMER GROUP ID AND GROUP NAME

MAGENTO – GET CUSTOMER GROUP ID AND GROUP NAME

The customer/user group determines which give discounts to customer/user, as defined by price rules, and the tax class that is connected with the group of customer/user. The default customer/user groups are General, Not Logged In, and Wholesale. you can also create new customer/user group with admin panel.

IN this post we will show you how to get group name and group id of customer/user in magento store. in 1st example we will get login customer/user group name and group id.

Example – 1

$customer_group_id = "2";
// Check if Customers/User is logged in
$customer_login = Mage::getSingleton('customer/session')->isLoggedIn(); 
if($customer_login)
{
	$customer_group_id = Mage::getSingleton('customer/session')->getCustomerGroupId(); 		
	
	// Get Customers/User Group ID
	echo "ID Of Group  ->  ".$customer_group_id;

	// Get Customers/User Group Name
	$customer_group = Mage::getModel('customer/group')->load($customer_group_id);
	echo "Name of Group  -> ".$customer_group->getCode(); 
}
else
{
	echo "Customers/User is Not logged in!!!";
}

Example – 2

By using this code you can get customer/user group name form the group id. we have to pass group id and it will give name of group.

$customer_group_id = "2";
   
// get name of Customers/User group    
$customer_group_name = Mage::getModel('customer/group')->load($customer_group_id)->getCustomerGroupCode();

Example – 3.
In this mehtod we will display all customer groups.

Get all customer groups

$groups_detail = Mage::getModel('customer/group')->getCollection();
foreach ($groups_detail as $group_val) 
{

  echo 'ID of Customer Group  = '.$group_val->getCustomerGroupId().'
';
  echo 'Name of Customer Group  = '.$group_val->getCustomerGroupCode().'
';

}

Example – 4

Get all customer groups exteranl php

In this mehtod we will display all customer groups groups exteranl php.

error_reporting(E_ALL | E_STRICT);
$mage_file_name = 'app/Mage.php';
require_once $mage_file_name;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
// display errors in file
umask(0);
Mage::app('admin'); 

$groups_detail = Mage::getModel('customer/group')->getCollection();
foreach($groups_detail as $group_val) 
{

    echo 'ID of Customer Group  :'.$group_val->getCustomerGroupId().'
';
    echo 'Name of Customer Group :'.$group_val->getCustomerGroupCode().'
';

}

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US