I am using following code to create customer in magento 2 programmatically
namespace PackageName\ModuleName\Helper;
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
// here $total_obj is customer array i am getting from third party service
foreach($total_obj as $arr){
$customer = $customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->setEmail('[email protected]');
$customer->setFirstname('FirstName');
$customer->setLastname('LastName');
$customer->setPassword('123456789');
$customer->setLoginEmail('[email protected]');
$customer->save();
}
from the above code i am not able to set login_email value. all details getting saved but not this custom attribute is not saving.
Please let me know what i am doing wrong.
for creation custom attribute i had followed https://webkul.com/blog/how-to-create-customer-custom-attribute-in-magento-2-0/