如何以编程方式确认Magento中的用户?

时间:2010-08-05 16:42:12

标签: magento

我正在编写一个自动将用户导入magento的脚本。 这是一段代码:

$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId; 
$customer->setStore($store);

$customer->loadByEmail($riga[10]);

echo "Importo ".$data[0]."\n";
echo "  email :".$data[10]."\n";

$customer->setTaxvat($data[7]);
$customer->lastname =    $lastname;
$customer->email =       $data[10]; 
$customer->password_hash = md5($data[0]);

$customer->save();

问题是用户被创建为“未确认”,而我希望他们被“确认”。

我尝试过:

$customer->setConfirmation('1');
保存之前,它没有用。有人知道如何确认用户吗?

谢谢!

3 个答案:

答案 0 :(得分:17)

我认为setConfirmation()正在等待确认密钥。尝试传递null,我认为它会起作用吗?

只是为了澄清:

$customer->save();
$customer->setConfirmation(null);
$customer->save();

应强制确认。

答案 1 :(得分:4)

当我创建帐户时,它们已经确认,但已被禁用!这修好了它:

$customer->save();
$customer->setConfirmation(null);
$customer->setStatus(1);
$customer->save();

答案 2 :(得分:1)

保存整个模型非常昂贵。您只能保存非常快的确认属性:

$customer->setConfirmation(NULL);
$customer->getResource()->saveAttribute($customer, 'confirmation');