0

I have created a custom attribute in Customer Address (govt_id) and it is showing on Adminhtml UI, but when I retrieve the customer address attributes it's not getting it.

my setup code:

<?php

$this->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');


$setup->addAttribute('customer_address', 'govt_id', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'GOVT ID',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => '0',
    'visible_on_front' => 0,
));

Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'govt_id')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))->save();

$this->endSetup();

And i'm getting attributes by using below code

$magentoAttributes = Mage::getModel('customer/address')->getAttributes();
        foreach(array_keys($magentoAttributes) as $att)
        {
            $name = $att;
            $this->magentoOptions[$att] = $name;

        }
        Mage::log( $this->magentoOptions);

Result:

2015-09-14T06:35:15+00:00 DEBUG (7): Array
(
    [entity_id] => entity_id
    [entity_type_id] => entity_type_id
    [increment_id] => increment_id
    [parent_id] => parent_id
    [attribute_set_id] => attribute_set_id
    [created_at] => created_at
    [updated_at] => updated_at
    [prefix] => prefix
    [firstname] => firstname
    [middlename] => middlename
    [lastname] => lastname
    [suffix] => suffix
    [company] => company
    [street] => street
    [city] => city
    [country_id] => country_id
    [region] => region
    [region_id] => region_id
    [postcode] => postcode
    [telephone] => telephone
    [fax] => fax
    [vat_is_valid] => vat_is_valid
    [vat_request_id] => vat_request_id
    [vat_request_date] => vat_request_date
    [vat_request_success] => vat_request_success
    [vat_id] => vat_id
)

Here the govt_id attribute is missing.

I have cleared cache also, but still it's not getting Why?

Did I do anything wrong or is something missing?

  • I have updated my answer plz check it . – Arunendra Sep 14 '15 at 7:49
1

Set visible_on_front to 1

Change it from:

$setup->addAttribute('customer_address', 'govt_id', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'GOVT ID',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => '0',
    'visible_on_front' => 0,
));

To :

$setup->addAttribute('customer_address', 'govt_id', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'GOVT ID',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'default' => '',
    'source' =>   NULL,
    'visible_on_front' => 1
));

For More detail see here:
Adding custom attribute to Customer

0

To verify this,

Check tables

  1. eav_attribute if there is a row with attribute_code = govt_id and entity_type_id as 1

  2. If 1 is no, then attribute has not been created, if yes check now in table customer_eav_attribute if the attribute_id exists

  3. If 2 is yes, you have successfully created a customer entity attribute

  4. Check in table customer customer_form_attribute (this is to check if for the forms you have added an entry has been added to this table)

Check if 3 if the above points are verified, you should have successfully created a customer entity attribute

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.