3

Before upgrading to Magento 2.2.1, I was using version 2.1.10 and made a custom uuid attribute for customers. The attribute was added to the customer form in the admin panel and saved correctly. However after upgrading to 2.2.1, the attribute no longer shows in the form. It is still present in the eav_attributes db table so I'm not sure what has changed.

This is my code used to initial setup the attribute:

public function __construct(CustomerSetupFactory $customerSetupFactory,
                            AttributeSetFactory $attributeSetFactory)
{
    $this->customerSetupFactory = $customerSetupFactory;
    $this->attributeSetFactory = $attributeSetFactory;
}

public function install(ModuleDataSetupInterface $setup,
                        ModuleContextInterface $context)
{
    /** @var CustomerSetup $customerSetup */
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
    $setup->startSetup();
    $attributesInfo = [
        'uuid' => [
            'label' => 'UUID',
            'type' => 'varchar',
            'input' => 'text',
            'position' => 1000,
            'visible' => true,
            'required' => false,
            'system' => 0,
            'user_defined' => true,
            'unique' => true,
        ]
    ];
    $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
    $attributeSetId = $customerEntity->getDefaultAttributeSetId();
    /** @var $attributeSet AttributeSet */
    $attributeSet = $this->attributeSetFactory->create();
    $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
    foreach ($attributesInfo as $attributeCode => $attributeParams) {
        $customerSetup->addAttribute(Customer::ENTITY, $attributeCode, $attributeParams);
    }
    $magentoUuidAttribute = $customerSetup->getEavConfig()
        ->getAttribute(Customer::ENTITY, 'uuid');
    $magentoUuidAttribute->addData([
        'attribute_set_id' => $attributeSetId,
        'attribute_group_id' => $attributeGroupId,
        'used_in_forms' => ['adminhtml_customer'],
    ]);
    $magentoUuidAttribute->save();
    $setup->endSetup();
}

}

Any help would be greatly appreciated.

1

It seem to be visible only when there full 4 opitons of 'used_in_forms','customer_account_create','customer_account_edit', 'checkout_register','adminhtml_customer' . Don't worry because even when you set this. that attribute will not be visible in Register form

  • These values are set to false by default when an attribute is created. – Matthew Berends Dec 9 '17 at 1:48
  • It seem to be visible only when there enought 4 opiton of 'used_in_forms' 'customer_account_create', 'customer_account_edit', 'checkout_register', 'adminhtml_customer' . Don't worry because even when you set this. that attribute will not be visible in Register form – Steve Pham Dec 9 '17 at 2:34
2

Create UI component xml file for that, File path and name should be : Namespace/Module/view/adminhtml/ui_component/customer_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="ATTRIBUTECODE" formElement="input">
            <settings>
                <visible>true</visible>
            </settings>
        </field>
    </fieldset>
</form>

Run commands : setup upgrade, cache clear and cache flush

  • Great! Just one note, there is no need to specify formElement (your code is forcing to render the field as a text input) – Raul Sanchez Feb 27 at 10:51

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.