Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically confirm a user in Magento?

Tags:

magento

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[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!

like image 506
fdierre Avatar asked Aug 05 '10 16:08

fdierre


3 Answers

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.

like image 64
Nic Avatar answered Nov 15 '22 19:11

Nic


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();
like image 40
vahanpwns Avatar answered Nov 15 '22 18:11

vahanpwns


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');
like image 31
Tiberiu Avatar answered Nov 15 '22 17:11

Tiberiu