Get Customer Group Name from Customer Group ID

customer-grouporders

I need to use the customer group name in the invoice. Based on $order I can get the customer group ID.

$customerGroupId = $order->getCustomerGroupId();

I tried the following code:

$groupname = Mage::getModel(‘customer/customer_group’)->load($customerGroupId);

This results in the following error:

Fatal error: Call to a member function load() on a non-object

How can I get the group name?

Best Answer

The object I think you are looking for is Mage_Customer_Model_Group so you will need to update your load to use the following.

$groupname = Mage::getModel('customer/group')->load($customerGroupId)->getCustomerGroupCode();

On another note there is no name on customer groups but instead 'customer_group_code'. With the default data that comes with Magento the codes look as follows.

NOT LOGGED IN, General...etc

To get the code you can either call getCustomerGroupCode or there is a function getCode which is simply an alias for the first one.

Related Topic