public function addCustomer($data) {
Mage::app()->setCurrentStore(1);
$websiteId = 1;
$store = Mage::app()->getStore();
if (!$this->customerExists($data['email'])) {
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId = $websiteId;
$customer->setStore($store);
$old_password = $this->randomPassword();
// If new, save customer information
$customer->setData('firstname',$data['firstname']);
$customer->setData('lastname' , $data['lastname']);
$customer->setData('email',$data['email']);
$customer->setPassword($old_password);
$customer->setData('old_password', $old_password);
$customer->save();
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "update old_customer set status = 1 where email = ?";
$write->query($sql,array($data['email']));
var_dump($customer->getEmail() . ' import successed. password:' . $customer->getOldPassword());
}
}
生成随机的密码
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}