0

I am using magento 2.3.2 version.

I need to remove the Firstname and Lastname fields in the new customer creation/ registration API. I referred this link

  • 1
    It's mandatory to add firstname and lastname while creating customer. The one way which you can use for this is:- create a hidden field for firstname and lastname and add some static value in it.. like Guest User or Test User – temper Aug 20 at 10:10
0

Firstname and Lastname are mandatory fields for the customer, So you have to set some value for these fields during registration, at least some dump value like (-), etc..

So,if you DO NOT want to provide these two fields value during hitting the API point /V1/customers then you have to work on Magento\Customer\Api\AccountManagementInterface,Create a plugin on createAccount() and set some dump value to Firstname and Lastname to this field.

Plugin Class

<?php
namespace StackExchange\Magento\Plugin;

use Magento\Customer\Api\Data\CustomerInterface;

class AccountManagementPlugin 
{
    public function beforeCreateAccount(
        \Magento\Customer\Api\AccountManagementInterface $subject,
        CustomerInterface $customer,
        $password = null,
        $redirectUrl = ''
    ){
        // Set dump value to - to firstName and last Name
        if($customer->getFirstname() == null){
            $customer->setFirstname('-');
        }
        if($customer->getLastname() == null){
            $customer->setLastname('-');
        }       
        return [$customer,$password,$redirectUrl];
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.