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

Fix Customer custom attributes lost after save #17968

Merged
merged 3 commits into from
Oct 12, 2018
Merged

Fix Customer custom attributes lost after save #17968

merged 3 commits into from
Oct 12, 2018

Conversation

Thundar
Copy link
Contributor

@Thundar Thundar commented Sep 7, 2018

Description

The customer model has an attribute attribute_set_id that links to its attribute set. It is used while saving, as there is a check to see if its attributes are in the set or not, using this link.
We want to avoid a null attribute_set_id.

Fixed Issues

  1. Saving Customer Model directly causes loss of data #12479: Saving Customer Model directly causes loss of data

Manual testing scenarios

  1. Disable EAV cache.
  2. Create a custom attribute for Customer entity.
  3. Update a customer in the admin and add a value for this new attribute.
  4. Programmatically load the customer, make some change (e.g. firstname) and then save directly using the model.
  5. Reload the customer: the custom value is not lost.

No regression manual test:
6. Programmatically load the customer, add a different not-yet-defined attribute to customer (e.g. setNotYetDefined(1)) and save directly using the model.
7. Reload the customer: the custom value is still not lost, while not_yet_defined is lost.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Sep 7, 2018

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @Thundar. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me {$VERSION} instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@Thundar Thundar changed the title Customer custom attributes lost after save Fix Customer custom attributes lost after save Sep 7, 2018
@Thundar
Copy link
Contributor Author

Thundar commented Sep 13, 2018

Maybe related evolution: #4677
Surely related: #4694
By the comments, it should be already fixed on 2.3, but I cannot check it.

@slavvka
Copy link
Member

slavvka commented Oct 2, 2018

Hey @Thundar. Thank you for the contribution. I have a question though. As far as I can see attribute_set_id should be pre-populated on customer instance creation (and exists during whole customer object life cycle). That gives us required variable set and a possibility to extend. I am not sure that having the code pre-population run every time you save customer is a good idea. Please consider refactoring it to pre-populate this variable in the factory, for example. Moreover the address model also may have the similar issue, that is also would be good to have fixed. And in that case the original code that you copied from updateData would be also not needed. Does it make sense?

@Thundar
Copy link
Contributor Author

Thundar commented Oct 3, 2018

Hello @slavvka , thank you for your answer and the hints. They makes sense.
The nuisance is that the same code is both in CustomerRepository::save function and in Customer::updateData. I see that having a third replication would be worst.

The Address model benefits of a custom getAttributeSetId method (since MAGETWO-69111) that make it always not null: I added the same to the customer. This looks me the cleaner way (and it is easy to navigate). I think this is the best way to grant extendibility.
I also removed unused code.

@slavvka
Copy link
Member

slavvka commented Oct 3, 2018

Hey @Thundar. You are right. Thank you for the contribution. Would you mind to port the PR to 2.3 as well? You could do it now or after this PR is merged with the special tool.

@magento-engcom-team magento-engcom-team added this to the Release: 2.2.8 milestone Oct 3, 2018
@magento-engcom-team
Copy link
Contributor

Hi @slavvka, thank you for the review.
ENGCOM-3082 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @Thundar. Thank you for your contribution.
We will aim to release these changes as part of 2.2.8.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants