Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top