How Do I Get Customer Custom Attribute Value

How Do I Get Customer Custom Attribute Value

July 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How Do I Get Customer Custom Attribute Value

Retrieving Customer Custom Attribute Values in Magento

As a senior developer, I often encounter situations where we need to retrieve custom attribute values for customers in Magento. This can be particularly tricky when dealing with attributes that store string or text data.

Understanding the Current Issue

The issue you’re facing is common among developers new to Magento’s object-relational mapping (ORM) and database structure. You’ve correctly identified that the attribute_id of 477 corresponds to a currency attribute, but you’re struggling to get Magento to return the actual string value (“USD”) instead of just the integer (161).

Digging Deeper into Magento’s ORM

Magento uses its own ORM to interact with the database. When you call $customer->getDefaultCurrency(), it retrieves the default currency ID from the customer_entity table for the current customer.

However, this doesn’t directly relate to the string value stored in other tables like customer_eav, customer_entity_varchar, or customer_entity_text. These tables store the actual attribute values, but accessing them requires a different approach.

Accessing Custom Attribute Values

To retrieve custom attribute values, you can use Magento’s attribute model and collection. Here’s how:

$customer = $session->getCustomer();
$attributeId = 477; // Replace with your desired attribute ID
$attributeModel = Mage::getSingleton('eav/config')->getAttribute('customer', 'currency'); // Assuming currency is the attribute code

if ($attributeModel->usesSource()) {
    $values = $attributeModel->getSource()->getAllOptions(false);
    $optionIdToValue = array_combine(array_column($values, 'value'), array_column($values, 'label'));

    $customAttributeValue = $optionIdToValue[$customer->getCurrency()];
} else {
    $customAttributeValue = $customer->getCurrency();
}

In this code:

  • We retrieve the customer object using your existing $session->getCustomer() method.
  • We set the attribute_id to 477 (or whatever ID corresponds to the attribute you want).
  • We use Magento’s configuration model to get a handle on the attribute itself, which includes meta information like whether it uses a source (like a dropdown or multiselect field).

We then check if the attribute uses a source. If it does, we retrieve all the options for that source and create an array mapping option IDs to their corresponding labels (string values). Finally, we look up the customer’s value in this map to get the actual string representation of the currency.

Conclusion

Retrieving custom attribute values in Magento requires understanding how the ORM interacts with the database. While the default methods might not always give you what you need, using the eav/config model and checking if an attribute uses a source can help you retrieve the correct string value for any customer attribute.

Remember to replace 'currency' in the getAttribute() call with your actual attribute code. You can find this in Magento’s admin interface under “Customers” -> “Attributes”.

For more advanced use cases or customizations, I recommend checking out our guide on Customizing Magento’s ORM Behavior for a deeper dive into how Magento’s data access works.

Database Configuration Customers Pricing

Our network