0

I have created a custom REST API to create a customer account programmatically. Now while creating a customer account user may or may not have an email ID. But user will update while placing order in the checkout page. (Magento Headless Implementation)

So Is there any way to avoid adding a customer email ID only while creating account.

Below is my code to create customer Account.

    $customerData = $this->customerFactory->create();
    $customerData->setEmail("EMAIL_HERE"); // This could be blank sometime.
    $customerData->setFirstname("FIRST_NAME_HERE");
    $customerData->setFirstname("LAST_NAME_HERE");
    $customerData->setCustomAttribute('custom_attribute_code_here', 'Value_here');
    $this->customerRepository->save($customerData);

Note: All above values I will be getting in a REST API request.

I see the below changes would be required:

  1. make the customer "email" attribute as not required from eav table via patch script.
  2. Override Core Files as below Magento\Customer\Model\ResourceModel\Customer.php; beforeSave()

I am assuming there will be more core files to override that I am still looking into it. I know this is not a right requirement. But still I want to see what are the modification needed and what are the challenges and what would be issues if somehow we make this happen.

Your Answer

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

Browse other questions tagged or ask your own question.