How to create a customer account programmatically?

How to create a customer account programmatically?

Add below code on your php file

use Magento\Framework\App\RequestFactory;

use Magento\Customer\Model\CustomerExtractor;

use Magento\Customer\Api\AccountManagementInterface;

public function __construct(

RequestFactory $requestFactory,

CustomerExtractor $customerExtractor,

AccountManagementInterface $customerAccountManagement,

Context $context

) {

$this->requestFactory = $requestFactory;

$this->customerExtractor = $customerExtractor;

$this->customerAccountManagement = $customerAccountManagement;

parent::__construct($context);

}



$customerData = [

'firstname' => 'abc' ,

'lastname' => 'xyz',

'email' => '[email protected]',

];

$password = null;

$request = $this->requestFactory->create();

$request->setParams($customerData);

$customer = $this->customerExtractor->extract('customer_account_create', $request);

$customer = $this->customerAccountManagement->createAccount($customer, $password);



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.