0

I created a new field on the customer form in the admin. I did so, with an EAV attribute like this inside the InstallData:

$customerSetup->addAttribute(Customer::ENTITY, self::DOCUMENT_NUMBER, [
        'type' => 'varchar',
        'label' => 'Document Number',
        'input' => 'text',
        'required' => true,
        'visible' => true,
        'user_defined' => true,
        'searchable' => true,
        'visible_on_front' => true,
        'unique' => true,
        'sort_order' => 31,
        'position' => 31,
        'system' => 0,
    ]);

It worked and I can see and save data using the customer form. The problem is that whenever I try to edit a costumer, it throws an error saying: The value of attribute "Document Number" must be unique. This would make sense if I were trying to create a new customer with an already used 'Document Number' but since I'm doing an updated on an existing record it should not give me this error.

Am I missing some configuration? Thanks.

0

since every customer has the value NULL for this attribute when you just created it, this error seems totally reasonable.

For example, if you have two customers in your shop, and add the attribute, both customers have the value NULL for this.

Now, if you edit one customer, and don't set the attribute, it still has NULL as value and the validation throws an error since it is not unique (because the other customer also has NULL)

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.