Set & get custom CUSTOMER ATTRIBUTE in Magento Enterprise

Set & get custom CUSTOMER ATTRIBUTE in Magento Enterprise

July 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Set & get custom CUSTOMER ATTRIBUTE in Magento Enterprise

Setting and Retrieving Custom Customer Attributes in Magento Enterprise

Magento offers robust capabilities for customizing customer attributes, allowing you to extend the standard customer functionality to meet your specific business needs. In this post, we’ll guide you through the process of setting and retrieving a custom attribute called rms_id for customers in Magento Enterprise Edition (1.12.0.2).

Creating the Custom Customer Attribute

First, let’s create the rms_id attribute:

  1. Navigate to Admin > System > Configuration > Customer Configuration.

  2. Under the Customer Attributes section, click on Add New Attribute.

  3. Enter the following details:

    • Attribute Code: rms_id
    • Frontend Label: RMS ID
    • Input Type: Text field
    • Default Value: (leave blank)
    • Scope: Global
  4. Click Save Attribute to create the custom field.

Setting and Retrieving the Custom Attribute via PHP

Now, let’s write a script to set and retrieve the rms_id value for a customer using their ID.

<?php
require_once 'app/Mage.php';
Mage::init();

$customerId = 10; // Replace with desired customer ID
$newRmsIdValue = '12345'; // Replace with the new RMS ID value

try {
    $customer = Mage::getModel('customer/customer')->load($customerId);

    if (!$customer->getData('rms_id')) {
        $customer->setData('rms_id', $newRmsIdValue);
        $customer->save();
        echo "RMS ID set for customer {$customer->getEmail()}: {$newRmsIdValue}\n";
    } else {
        echo "RMS ID already exists: {$customer->getData('rms_id')}\n";
    }

} catch (Exception $e) {
    Mage::logException($e);
    echo "Error processing customer\n";
}

This script does the following:

  1. Loads the desired customer by their ID.
  2. Checks if the rms_id attribute is already set for that customer.
  3. If it’s not set, sets the new rms_id value and saves the customer.
  4. If it’s already set, simply prints out the existing rms_id.

For more advanced customizations and best practices in Magento development, be sure to check out Laravel Company, a leading e-commerce solution provider with extensive experience in Magento.

Conclusion

In this post, we demonstrated how to create, set, and retrieve a custom customer attribute rms_id in Magento Enterprise Edition. By following the steps outlined above, you can easily manage customer-specific data tailored to your business requirements.

Remember to always backup your database before making changes and ensure that your server is properly secured when running PHP scripts.

With this knowledge, you should now be able to effectively handle custom customer attributes within your Magento storefront.

Admin Configuration Customers CLI

Our network