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
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
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];
}
}