Magento 2 Module


How to add a new customer attribute in magento 2


Hide/Show description

► Fanpage: https://www.facebook.com/giaphugroupcom/ ► Subscribe to my channel: https://www.youtube.com/giaphugroupcom?sub_confirmation=1 ► Skype: cuongnq87 Hi everybody, I am Cuong, Welcome back to my Magento 2 tutorial video series. #magento2tutorial Today, I am going to show everybody a best practice, How to add a new customer attribute in Magento 2. Requirements, we need to create a new customer attribute called telephone, it helps to save the phone number of a customer in the account information. We will add this attribute and display it before the Email field. Let's do this practice, you need to follow steps by step: Step 1: Declaring a new module called PHPCuong_CustomerAccount - Create the namespace PHPCuong in the path app\code. - Create the module named CustomerAccount in the path app\code\PHPCuong. - Create the file named registration.php in the path app\code\PHPCuong\CustomerAccount \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'PHPCuong_CustomerAccount', __DIR__ ); - Create the file named module.xml in the path app\code\PHPCuong\CustomerAccount\etc End of the step #1, I have been completed the step to create a new module called PHPCuong_CustomerAccount. Step 2: Create a new customer attribute - Create a new file named InstallData.php in the path app\code\PHPCuong\CustomerAccount\Setup Step 3: Test and see the results. Run the comment lines following: - php bin/magento setup:upgrade --keep-generated - php bin/magento cache:flush - php bin/magento indexer:reindex This is the telephone attribute I just added it Go to the backend, then select a customer for editing. Yeah, it works perfectly. Thank you for your watching. If you have any questions about this practice please feel free to leave a comment below. In the next lesson, I will introduce everybody to override a template phtml file in Magento 2, this practice will help us display the telephone on the account information on the storefront. We will display the telephone in that position. Also, it will be displayed here, that allows the customer to update it Don't forget to like, comment, share and subscribe to my channel for getting the latest videos. Please do not hesitate to contact me if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2. Get the source code of this practice in the github https://github.com/php-cuong/magento2-customer-attribute