Skip to content

Customer with unique attribute can't be saved #7844

Closed
@bartlubbersen

Description

@bartlubbersen

Preconditions

  1. Magento 2.1.3 (Did not test if it is also bugged in earlier versions)
  2. PHP7

Steps to reproduce

  1. Add an extra customer attribute, that should be unique. In my case an ERP id. Attribute is correctly added to the form and attribute set and is saving correctly.
  2. Set a value for this attribute for a customer and save it.
  3. After the value is saved and you will try to save that same customer again you get an error the value should be unique.

Expected result

  1. The customer should be saved cause the value is unique.

Actual result

  1. Error message in admin: 'The value of attribute "Attribute label" must be unique'

Comment

  1. I did some digging in the actual code and the problem seems to be that in the function "checkAttributeUniqueValue" in class "Magento\Eav\Model\Entity\AbstractEntity" in the end it is trying to get the object ID and compare it to the value for which a match was found. However the object->getId always returns null because it is not set.
    The reason it is not set I can trace back to "Magento\Customer\Controller\Adminhtml\Index\Validate" where in the "_validateCustomer" function the customer object passed to the validate function already is missing an ID.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentRelease Line: 2.1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions