Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer with unique attribute can't be saved #7844

Closed
bartlubbersen opened this issue Dec 16, 2016 · 5 comments
Closed

Customer with unique attribute can't be saved #7844

bartlubbersen opened this issue Dec 16, 2016 · 5 comments
Assignees
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1

Comments

@bartlubbersen
Copy link
Contributor

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.
@veloraven
Copy link
Contributor

@bartlubbersen thank you for your feedback.
Customer custom attributes are available in Enterprise edition only.
If you use this one, please contact Magento support instead of posting your issue here. Github is intended for Community edition reports given no account management for CE users. This will allow for proper tracking of issues at the account level.
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 amd we can not treat it as an issue.

@bartlubbersen
Copy link
Contributor Author

@veloraven we are not using Enterprise functionality but we are not adding the attributes through the back-end either. We are just adding attributes through setup scripts which should work also for community. Otherwise no thirth party extension could ever create a customer attribute. So I think this issue should be reopened. If you agree adding attributes via setup should work please also reopen ticket #7845 because it is about almost the same thing but not about customer, but about customer address.

@ericrisler
Copy link
Contributor

ericrisler commented Mar 9, 2017

@bartlubbersen
The \Magento\Customer\Controller\Adminhtml\Index\Validate::_validateCustomer() method uses the \Magento\Customer\Model\Metadata\Form::extractData() method to pull out the submitted form data in the admin. This method returns a data array of attribute_code=>values but excludes the 'entity_id' value. Later in the validation call stack, this causes the validation to fail. Set a breakpoint in \Magento\Eav\Model\Entity\AbstractEntity::checkAttributeUniqueValue() to watch. Or just look at the line that looks for an id: if ($object->getId())...if the data had contained the entity_id then we would pass validation.

We overrode the \Magento\Customer\Controller\Adminhtml\Index\Validate::_validateCustomer() method and added the entity_id:

$this->dataObjectHelper->populateWithArray(
    $customer,
    $data,
    '\Magento\Customer\Api\Data\CustomerInterface'
);

// fix:
$submittedData = $this->getRequest()->getParam('customer');
$entity_id = $submittedData['entity_id'];
$customer->setId($entity_id);

$errors = $this->customerAccountManagement->validate($customer)->getMessages();

@Esraa-AlArmouti
Copy link

I had "The value of Admin must be unique." message whenever I want to save the attribute.
eventually magento 2.1.3 doesn't save the attribute if one of its options under "Manage Options (Values of Your Attribute)" is not a unique value for admin field, so basically admin fields should be unique and make sure if it has capital letters or ever special characters. I've made a collection of small letters and number for each admin field and it has been saved successfully.
p.s.: check if Advanced Attribute Properties > Unique Value is No. if not make it as No.
I hope this solution help somebody.

@ishakhsuvarov ishakhsuvarov reopened this May 20, 2017
storbahn added a commit to teamneusta/magento2 that referenced this issue May 20, 2017
storbahn added a commit to teamneusta/magento2 that referenced this issue May 21, 2017
magento-team pushed a commit that referenced this issue Jun 1, 2017


 - Merge Pull Request #9712 from teamneusta/magento2:issue-7844
magento-team pushed a commit that referenced this issue Jun 1, 2017
[EngCom] Public Pull Requests
 - MAGETWO-69573: Adding logo in media folder #9797
 - MAGETWO-69555: Allow for referenceBlock to include template argument #9772
 - MAGETWO-69540: Fix for #5897: getIdentities relies on uninitialized collection #9777
 - MAGETWO-69533: [BUGFIX][6244] Fix Issue with code label display in cart checkout. #9721
 - MAGETWO-69499: Update select.js #9475
 - MAGETWO-69451: Replace Zend_Json in the configurable product block test #9753
 - MAGETWO-69373: Customer with unique attribute can't be saved #7844 #9712
 - MAGETWO-69369: Replace the direct usage of Zend_Json with a call to the Json Help class #9344
 - MAGETWO-69085: Do not hardcode product link types #9600
 - MAGETWO-69554: Patch to allow multiple filter_url_params to function #9723
@magento-team magento-team added Release Line: 2.1 Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development develop labels Jul 31, 2017
@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-69373

@magento-engcom-team magento-engcom-team added Release Line: 2.1 Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development develop Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Fixed in 2.2.x The issue has been fixed in 2.2 release line labels Sep 11, 2017
magento-devops-reposync-svc pushed a commit that referenced this issue Aug 30, 2022
…h-module

[Pyrrans] AC-2643: OpenSearch module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1
Projects
None yet
Development

No branches or pull requests

10 participants