开发者

How to programmatically confirm a user in Magento?

开发者 https://www.devze.com 2023-01-10 04:28 出处:网络
I am writing a script that automatically imports users into magento. Here is a code snippet: $customer = Mage::getModel(\"customer/customer\");

I am writing a script that automatically imports users into magento. Here is a code snippet:

$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开发者_如何学Go[7]);
$customer->lastname =    $lastname;
$customer->email =       $data[10]; 
$customer->password_hash = md5($data[0]);

$customer->save();

The problem is that the users are created as "not confirmed", while I would like them to be "confirmed".

I tried with:

$customer->setConfirmation('1');

before the save, but it didn't work. Does anybody know how to confirm the user?

Thanks!


I think setConfirmation() is waiting for a confirmation key. Try passing null and I think it will work?

Just to clarify:

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

Should force confirmation.


When I created accounts, they were already confirmed, but they were disabled! This fixed it:

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


Saving the entire model is expensive. You can save only the confirmation attribute which is very fast:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号