Magento 2 provides a feature in which the admin/merchant can add extra address fields in the registration form.
This feature works in the following scenarios…
Given below are the scenarios in which it works as intended.
- When an Admin creates a new customer in the backend, the customer custom address attribute is saved.
- When an Admin updates an existing customer account/custom address attribute, then the attribute is saved.
- In the frontend, if an existing customer edits and updates the custom address attribute, it is saved successfully.
But, when a new customer registers for the first time and if he provides address information in the custom field, it is not saved successfully in the database.
This article provides a solution to fix this issue and to save the information entered in the custom attribute in the database.
The following changes have been done in below mentioned files. Please check the line numbers.
Line No 130:
The coding of the lines from 132 to 134 has been modified.
Remove the extractAddress() method code from line 194 – 237 in the Createpost.php file
And add the following code to that file
Include RegionInterface and RegionFactory class to this file.
Create a RegionFactory variable
Assign RegionFactory class as a variable in construct method
Add extractAddress method
Here you have to add one new method called updateRegionData($attributeValues) to get the region_id.
That’s it. Clear the Magento cache and now the Customer Custom Address Attribute value will be saved in the database.
Hope this helps you to fix this issue. If you have any queries regarding the code, please let us know in the comment section below. We will be more than happy to help you.
LOOKING OUT FOR A MAGENTO AGENCY ?
- Ensure smooth, fast & frictionless buying experience
- Increase transaction success