How can i get user by his email, or return null if not found? I need to do this in cron.
This code works
$CustomerModel = $objectManager->create('\Magento\Customer\Api\CustomerRepositoryInterface');
try {
$customerExists = $CustomerModel->get($email); //Here 1 means Store ID**
} catch (Exception $e) {
$customerExists = false;
}
But once I run it via cron, it returns an error that email is already in use, even when in try/catch block.
Any ideas?