User can delete own account

0
28
views
Advertisement

if u want to give functionality to user to delete their own account ::

in  appcodecoreMageCustomercontrollersAccountController.php

add below action

public function deleteAction()
{
$customerId = $this->getRequest()->getParam(‘id’, false);
$customerUrl = Mage::getSingleton(‘customer/session’)->getCustomer();
$temp = explode(“,”,$customerUrl);
$cust_id = $temp[1];   // user id from session

/* remove this condition if you use userid from session directly */
if($customerId != $cust_id)
{
$this->_redirect(‘/index’);
}
else {
if($customerId){
$customer = Mage::getModel(‘customer/customer’)->load($customerId);
$customer->delete(); // delete customer
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl()); // for loging out user
}

$this->_redirect(‘/index’);
}
}

pass current user id in query string or u can also take it fron session

also change in appcodecoreMageCustomerModelCustomer.php

in this function

protected function _beforeDelete()
{
// $this->_protectFromNonAdmin();  // comment this line
return parent::_beforeDelete();
}

comment $this->_protectFromNonAdmin();

– Mayank Zalavadia