I’m in the process of converting the data from an old website to a new website. I’m creating and populating customers inside a class that extends Mage_Shell_Abstract.
I want to load a customer if they already exist, or create them if they don’t:
$customer = Mage::getModel('customer/customer')->loadByEmail('none@gmail.com');
$customer->setFirstName('John');
$customer->setLastName('Smith');
$customer->save();
Will this code cause any errors if no customer already exists with this email?
Not sure exactly what’s meant by “magento model that doesn’t exist”, but if you’re referring to the
customer/customermodel, it should work.If you are within the
run()method, thenMage::app()has already run within the__construct()method ofMage_Shell_Abstract, so you’ll have access to all of the models and other magento features from within that context.So
getCustomerByEmail()will work just like it does normally, as well as all the other methods on that model or any other.You should be able to do: