0

This is how i created my custom customer attribute

$installer = new Mage_Customer_Model_Resource_Setup('core_setup');

$installer->startSetup();

//$installer->removeAttribute('customer', 'dotmailer_id');
if (!$installer->getAttribute('customer', 'dotmailer_id')) {
    $entityTypeId = $installer->getEntityTypeId('customer');
    $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
    $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

    $installer->addAttribute('customer', 'dotmailer_id', [
        'type'     => 'int',
        'input'    => 'text',
        'backend'  => '',
        'frontend' => '',
        'label'    => 'Dotmailer ID',
        'visible'  => true,
        'required' => false,
        'user_defined' => 1,
        'source'   => ''
    ]);
    $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, 'dotmailer_id', '200');
    $attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'dotmailer_id');

    $attribute->setData('used_in_forms', [
        'customer_view',
        'adminhtml_customer',
        'customer_account_edit'
    ])
        ->setData('is_used_for_customer_segment', true)
        ->setData('is_system', 0)
        ->setData('is_user_defined', 1)
        ->setData('is_visible', 1)
        ->setData('sort_order', 99)
    ;
    $attribute->save();
}
$installer->endSetup();

The customer attribute is saved, but for some reason I cannot edit the show on front end part. see img: enter image description here . This is my first issue.

The second issue is: I went to a customer I gave a value to this new customer attribute and I save the customer. When I load the customer programmatically, like:

$customer = Mage::getModel('customer/customer')->load(12);
var_dump($customer->getData());

I don't get any values from my new customer attribute. It is not in the list with the rest of the attributes. Why ?

Thx

1 Answer 1

0

Try adding the 'visible_on_front' with value 1 in addAttribute params

like

$installer->addAttribute('customer', 'dotmailer_id', [
        'type'     => 'int',
        'input'    => 'text',
        'backend'  => '',
        'frontend' => '',
        'label'    => 'Dotmailer ID',
        'visible'  => true,
        'visible_on_front' => 1,
        'required' => false,
        'user_defined' => 1,
        'source'   => ''
    ]);

and change the value of user_defined as 0 in it.

Please check this once.

1
  • Thx a lot !, I don't know how i missed that May 2, 2017 at 12:40

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.