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', '>='))
{
Mage::getSingleton('eav/config')
->getAttribute('customer', 'foundation')
->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register'))
->save();
}
$installer->endSetup();
Options for select box
<?php
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"?>
<config>
<modules>
<Npm_Foundation>
<version>0.1.0</version>
</Npm_Foundation>
</modules>
<admin>
<routers>
<foundation>
<use>admin</use>
<args>
<module>Npm_Foundation</module>
<frontName>foundation</frontName>
</args>
</foundation>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<foundation>
<file>foundation.xml</file>
</foundation>
</updates>
</layout>
</adminhtml>
<global>
<fieldsets>
<checkout_onepage_quote>
<customer_foundation>
<to_customer>foundation</to_customer>
</customer_school>
</checkout_onepage_quote>
<customer_account>
<foundation>
<to_quote>customer_foundation</to_quote>
</foundation>
</customer_account>
</fieldsets>
<foundation_setup>
<setup>
<module>Npm_Foundation_Model_Entity_Setup</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
</foundation_setup>
<models>
<foundation>
<class>Npm_Foundation_Model</class>
<resourceModel>foundation_mysql4</resourceModel>
</foundation>
<foundation_mysql4>
<class>Npm_Foundation_Model_Mysql4</class>
<entities>
<foundation>
<table>foundation</table>
</foundation>
</entities>
</foundation_mysql4>
</models>
<resources>
<foundation_setup>
<setup>
<module>Npm_Foundation</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</foundation_setup>
<foundation_write>
<connection>
<use>core_write</use>
</connection>
</foundation_write>
<foundation_read>
<connection>
<use>core_read</use>
</connection>
</foundation_read>
</resources>
<blocks>
<foundation>
<class>Npm_Foundation_Block</class>
</foundation>
</blocks>
<helpers>
<foundation>
<class>Npm_Foundation_Helper</class>
</foundation>
</helpers>
</global>
</config>
But I am not getting the attribute in collection.
Its showing perfectly in admin customer edit section.
Where I am wrong?
customer_entity_int
table if the correct value is saved with all the correct relations? (entity ID, attribute ID etc)