I have created an custom select attribute to the customer, Everything is working fine. the attribute save from register and checkout page.

But I wanted to display it in customer dashboard, When I say $customer = Mage::getSingleton('customer/session')->getCustomer() My custom attribute is not in this $customer. Here is my code

upgrade script

$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'foundation', array(
    'type' => 'int',
    'input' => 'select',
    'label' => 'Foundation',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => '0',
    'visible_on_front' => 1,
        'source'=> 'foundation/entity_foundation',
if (version_compare(Mage::getVersion(), '1.6.0', '<='))
      $customer = Mage::getModel('customer/customer');
      $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
      $setup->addAttributeToSet('customer', $attrSetId, 'General', 'foundation');
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
    ->getAttribute('customer', 'foundation')
    ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))

Options for select box

class Npm_Foundation_Model_Entity_Foundation extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
    public function getAllOptions()
        $optionCollections = Mage::getModel('foundation/foundation')->getCollection();
        $options = array();
        foreach ($optionCollections as $foundations) {
            $options[] = array(
                'value' => $foundations->getData('foundation_id'),
                'label' => $foundations->getData('name_fr'));
        return $options;

I am trying to get it in customer dashboard as below

$customer = Mage::getSingleton('customer/session')->getCustomer();

Even I tried this also

$customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
 $customer = Mage::getModel("customer/customer")->load($customerId);

added config.xml code

<?xml version="1.0"?>

But I am not getting the attribute in collection.

Its showing perfectly in admin customer edit section.

Where I am wrong?

  • Can you save a value with a customer and check in the customer_entity_int table if the correct value is saved with all the correct relations? (entity ID, attribute ID etc) Commented Sep 11, 2015 at 6:48
  • @SanderMangel, Yes, I am getting the value in backend, When I try to edit from admin. I am getting select box with proper value.
    – Charlie
    Commented Sep 11, 2015 at 6:59
  • ok so in the database it's saved correctly? Commented Sep 11, 2015 at 7:17
  • @SanderMangel, Yes
    – Charlie
    Commented Sep 11, 2015 at 7:18
  • @SanderMangel, you are right, its not saving.. I have just created another customer and checked in back end its showing same for all customer. How can save it ?
    – Charlie
    Commented Sep 11, 2015 at 7:29

1 Answer 1


I'm not too sure what's wrong with your script but here's one that works (just used it myself)

$installer = new Mage_Customer_Model_Entity_Setup('core_setup');


$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$installer->addAttribute('customer', 'foundation',  array(
    'input'         => 'select',
    'type'          => 'int',
    'backend'       => '',
    'label'         => 'Foundation',
    'source'        => 'foundation/entity_foundation',
    'visible'       => 0,
    'is_visible'    => 0,
    'required'      => 0,
    'default'       => '0',
    'frontend'      => '',
    'unique'        => 0,
    'user_defined'  => 0,

    '99'  //sort_order

$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "foundation");
$attribute->setData('used_in_forms', array('adminhtml_customer'));
  • I am getting error like Source model "foundation/entity_foundation" not found for attribute "foundation"
    – Charlie
    Commented Sep 11, 2015 at 7:38
  • @Charlie can you also post your config.xml Commented Sep 11, 2015 at 7:44
  • I have added the config.xml code
    – Charlie
    Commented Sep 11, 2015 at 7:53
  • @Charlie can you delete the attribute (from eav_attribute) and try again with source = Npm_Foundation_Model_Entity_Foundation Commented Sep 11, 2015 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.