我以编程方式添加了一个客户,并向该客户发送邮件以获取新密码。此外,在管理端,我找到了该客户,但当客户尝试使用电子邮件id和密码登录时,出现错误"登录或密码无效"这是我的代码这有什么问题?
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::init();
Mage::setIsDeveloperMode(true);
ini_set('memory_limit', '-1'); //for unlimited memory being more trickey
ini_set('display_errors', 1);
Varien_Profiler::enable();
umask(0);
Mage::app('default');
$customer_email = 'test@testemail.com'; // email adress that will pass by the questionaire
$customer_fname = 'test_firstname'; // we can set a tempory firstname here
$customer_lname = 'test_lastname'; // we can set a tempory lastname here
$passwordLength = 10; // the lenght of autogenerated password
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($customer_email);
/*
* Check if the email exist on the system.
* If YES, it will not create a user account.
*/
if(!$customer->getId()) {
//setting data such as email, firstname, lastname, and password
$customer->setEmail($customer_email);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword($customer->generatePassword($passwordLength));
}
try{
//the save the data and send the new account email.
$customer->save();
$customer->setConfirmation(null);
$customer->save();
$customer->sendNewAccountEmail();
}
catch(Exception $ex){
}
提前感谢。。。。
我猜它不会自动将客户设置为活动。您可以通过在数据库上运行此查询进行确认;
SELECT * FROM customer_entity WHERE email = 'the@email.com'
其中有一个名为"is_active"的列,几乎可以肯定地设置为0表示否。
在创建客户的脚本中,在保存之前添加此;
$customer->setIsActive(1);