How to programmatically confirm a user in Magento?

I am writing a script that automatically imports users in magenta. Here is the 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 users are created as “unconfirmed”, although I would like them to be “verified”.

I tried:

 $customer->setConfirmation('1'); 

before saving, but that didn't work. Does anyone know how to confirm a user?

Thanks!

+6
magento
source share
3 answers

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

Just clarify:

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

Confirmation of strength is required.

+16
source share

When I created the accounts, they were already verified, but they were disabled! This fixed this:

 $customer->save(); $customer->setConfirmation(null); $customer->setStatus(1); $customer->save(); 
+4
source share

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

 $customer->setConfirmation(NULL); $customer->getResource()->saveAttribute($customer, 'confirmation'); 
+1
source share

All Articles