I am trying to get custom attribute value of customer in observer, but no results. Can anyone help me:



 class  SSD_CustomerActivation_Model_Observer
        public function customerCustomerAuthenticated($observer)
             * @var $customer Mage_Customer_Model_Customer
            $customer = $observer->getEvent()->getModel();



$installer = $this;
$setup         = new Mage_Eav_Model_Entity_Setup('core_setup');
$attributeCode = 'customer_active';
$setup->addAttribute('customer', $attributeCode, array(
    'label'        => 'Is Active',
    'type'         => 'int',
    'input'        => 'boolean',
    'visible'      => true,
    'required'     => false,
    'position'     => 530,
$eavConfig   = Mage::getSingleton('eav/config');
$attribute   = $eavConfig->getAttribute('customer', 'is_active');
$usedInForms = array(
$attribute->setData('used_in_forms', $usedInForms);


The value does not appear because it's not set for that customer. When you add an attribute you to the customer, initially there are no values for it. You have to edit the customer in the admin panel and set that field to a value (yes or no in your case).
I have a feeling you are going to say that you already did that and still doesn't work. Here is why.
Your install script actually installs 2 attributes: customer_active and is_active. The first one is not available in any forms. The second one (is_active) is the one that appears in the backend, and you set the value for it. In the observer you check the value of customer_active.
I think you need to change this line in the installer:

$attribute   = $eavConfig->getAttribute('customer', 'is_active');

To this one:

$attribute   = $eavConfig->getAttribute('customer', 'customer_active');

and reinstall the module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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