Created
November 11, 2013 16:01
-
-
Save tegansnyder/7415555 to your computer and use it in GitHub Desktop.
An example of adding a new customer to Magento with a auto-generated password and custom welcome email.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // sending a custom password to customers | |
| require_once('app/Mage.php'); | |
| umask(0); | |
| Mage::app(); | |
| $store_id = Mage::app()->getStore()->getId(); | |
| $customer_email = 'some-customer@domain.com'; | |
| $customer_fname = 'John'; | |
| $customer_lname = 'Doe'; | |
| $passwordLength = 10; | |
| $customer = Mage::getModel('customer/customer'); | |
| $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); | |
| $customer->loadByEmail($customer_email); | |
| if (!$customer->getId()) { | |
| $customer->setEmail($customer_email); | |
| $customer->setFirstname($customer_fname); | |
| $customer->setLastname($customer_lname); | |
| $password = $customer->generatePassword($passwordLength); | |
| $customer->setPassword($password); | |
| try { | |
| $customer->save(); | |
| $customer->setConfirmation(null); | |
| $customer->save(); | |
| //$customer->sendNewAccountEmail(); | |
| $templateId = 10; | |
| $sender = Array('name' => Mage::getStoreConfig('trans_email/ident_general/name'), | |
| 'email' => Mage::getStoreConfig('trans_email/ident_general/email')); | |
| $store = Mage::app()->getStore(); | |
| $name = $customer_fname . ' ' . $customer_lname; | |
| $vars = Array('customer_name' => $name, | |
| 'new_password' => $password); | |
| $translate = Mage::getSingleton('core/translate'); | |
| Mage::getModel('core/email_template')->sendTransactional($templateId, | |
| $sender, | |
| $customer_email, | |
| $name, | |
| $vars, | |
| $store->getId()); | |
| $translate->setTranslateInline(true); | |
| } catch(Exception $e) { | |
| echo $e->getMessage(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment