1

I've create a custom attribute for the customer_address.

It is at backend:

$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerSetup->addAttribute('customer_address', 'my_id', [
    'label' => 'My label',
    'input' => 'text',
    'type' => 'int',
    'source' => '',
    'required' => false,
    'position' => 1000,
    'visible' => false,
    'system' => false,
    'is_used_in_grid' => false,
    'is_visible_in_grid' => false,
    'is_filterable_in_grid' => false,
    'is_searchable_in_grid' => false,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'my_id')
        ->addData([
            'used_in_forms' => ['adminhtml_customer_address']
]);
$attribute->save();

But the textbox is still appears on the forms where Address is.

Why?

I thought this will solve my problem:

'visible' => false,
1

Solutoin is the end of the my answer

Ok, finally I've debugged the whole addAtribute process.

The key is good: visible => false

The code here is not so consistent, see this in:

module-customer\Model\ResourceModel\Setup\PropertyMapper.php

public function map(array $input, $entityTypeId)
{
    return [
        'is_visible' => $this->_getValue($input, 'visible', 1),
        ....

It is wait for key visible, and transform it to is_visible don't ask me why.

In my case, the problem was that I've deleted the key from the eav_attribute table, downgrade the setup_module run setup:upgrade but no change.

This is because it has stored this in the customer_eav_attribute table.

For debugugging first I set it to true so it stuck there.

So I need to delete from there, repeat the whole process and after this it works.

EDIT

When I told works, I meant that the value of the is_visible in the table now is 0. Hurray!

:( Field appears. Need to dig deeper.

Solution

Facepalm. It was so obvious for me that visible means visibility.

The solition is to change the type hidden.

$customerSetup->addAttribute('customer_address', 'my_id', [
        ...
        'input' => 'hidden',
        ...
    ]);

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.