Magento2: Just display "saveable" Attributes in Customer Admin Form

Created on 18 May 2017  路  15Comments  路  Source: magento/magento2

Preconditions

  1. Install Magento 2.1.6
  2. Create a new customer attribute without adding it to any attribute set or attribute group programatically

Steps to reproduce

  1. Create a new customer or edit an existing one
  2. You will see your new attribute (which is NOT saveable because it can't be extracted in post request)

Expected result

  1. You shouldn't see the attribute unless you add it to "adminhtml_customer" (Table customer_form_attribute)

Actual result

  1. You see the attribute and you can't save it. This is very confusing.

You should filter all displayed attributes in the admin form. Just display attributes which can be saved. I've searched for hours until I found the missing entry...

Clear Description Format is valid Ready for Work needs update Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x

Most helpful comment

Create a new customer attribute without adding it to any attribute set or attribute group programatically

This is not an EE feature.

All 15 comments

@klein0r thank you for your feedback.
Which Magento edition do you use? As I can see you mention customer custom attributes.
Customer custom attributes are available in Enterprise edition only.
If you use this one, please contact Magento support instead of posting your issue here.
If you use Community Edition please address your question at programming questions forum or Magento Stack Exchange. As it is not a native behavior of Magento CE and we can not treat it as an issue

According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.

Sorry but this is a bit too easy. You say "additional customer attributes" is an enterprise feature? How do you ensure that there are no extensions in the marketplace that add additional customer attributes for CE?

Create a new customer attribute without adding it to any attribute set or attribute group programatically

This is not an EE feature.

@klein0r, thank you for your report.
We've created internal ticket(s) MAGETWO-78513 to track progress on the issue.

mageconf

@avelikdusgg thank you for joining. Please accept team invitation here and self-assign the issue.

Hi @klein0r
For create a customer attribute and don't show it on the edit form you should add attribute like this:

$eavSetup->addAttribute(
    \Magento\Customer\Model\Customer::ENTITY,
    'sample_attribute',
    [
        'type'         => 'varchar',
        'label'        => 'Sample Attribute',
        'input'        => 'text',
        'required'     => false,
        'visible'      => true,
        'user_defined' => true,
        'position'     => 999,
        'system'       => 0,
    ]
);

If you want to show the attribute on customer create/edit form, you should specify 'used_in_forms':

$sampleAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'sample_attribute');
$sampleAttribute->setData(
    'used_in_forms',
    ['customer_account_create', 'customer_account_edit']

);
$sampleAttribute->save();

More see here

If you add an attribute with 'user_defined' => false (or don't specify 'user_defined'), than attribute will show depending on the visible field.

@klein0r please tell me if you have helped the last comment for resolve your issue.

@magento-engcom-team Yes, hat was the expected behavior. But when I've opened the issue, all attributes were visible in the backend (even when the "used_in_forms" part wasn't executed / present in database).

@klein0r
Yes of course, if you don't specify 'user_defined' => true, than your attribute always will present in customer edit form.
You should add attribute with 'user_defined' => true, and specify where do you want to show by 'used_in_forms':

$sampleAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'sample_attribute');
$sampleAttribute->setData(
    'used_in_forms',
    ['customer_account_create', 'customer_account_edit']

);
$sampleAttribute->save();

I'm pretty sure that I've set user_defined to true. But I will test that :) Thanks a lot

@klein0r Tell me please if it helped solve your problem,
and If the problem is exhausted, please close the issue.
Thanks

@klein0r we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

Okay, it is working now.

  • when I set user_defined to 1, the attribute will never show up in the backend (even with added adminhtml_customer to used_in_forms) and independent from the visible attribute.
  • when I set user_defined to 0 everything works fine

Nevertheless, the name "user_defined" is a bit strange. You would never expect that this option will prevent your attribute from showing up in the admin.

Was this page helpful?
0 / 5 - 0 ratings