Delete users in Magento frontend

If you need the possibility to let the users delete their own accounts, you can use the following snippet in a corresponding controller or observer to delete users in frontend:

<?php

$oCustomer = $this->_getSession()->getCustomer();
if(!$oCustomer->getId()){
Mage::throwException($this->__('Cannot load customer!'));
}
//lie to mage ;-)
// @todo: Check, if there is a better way
Mage::register('isSecureArea', true);
$oCustomer->delete();
$this->_getSession()->clear();

//put things right again
Mage::unregister('isSecureArea');

 

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.