2

How can I delete a customer in magento by refering using its object from Mage::getModel("customer/customer") ?

I already researched in google and with the bad luck I found nothing.

3 Answers 3

17

If you want to delete the customer with some code that runs from the admin area, this should be enough:

$id = 5;//replace with desired id
//or
//$customer = Mage::getModel('customer/customer')->loadByEmail($email);
$customer = Mage::getModel('customer/customer')->load($id);
$customer->delete();

If you want to delete the customer from the frontend area you need to wrap the code above in this:

Mage::register('isSecureArea', true);
//code from above goes here
Mage::unregister('isSecureArea');
2
  • thank you @marius but I do it on the backend =) thank you for the info =)
    – Netorica
    Mar 10, 2014 at 10:44
  • very helpful - especially the hint concerning the isSecureArea
    – ESP32
    Oct 20, 2020 at 16:42
7

I find it out. customer is an EAV like products that can be deleted using delete() method. Just flag the object to be deleteable using $customer->setIsDeleteable(true) because the customer model class which is Mage_Customer_Model_Customer implements Mage_Core_Model_Abstract which contains the delete() method

I used the following codes below

$customer->loadByEmail('[email protected]');
$customer->setIsDeleteable(true);
$customer->delete();
1

Get Customer By Id

$id = 5;//replace with desired id
$customer = Mage::getModel('customer/customer')->load($id);

Get Customer By Email

$customer = Mage::getModel('customer/customer')->setWebsiteId(0)->loadByEmail($email);

Delete Customer

$customer->delete();
1
  • in above link get customer by Email is not corrent, thats why I have to mentioned above line Sep 17, 2015 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.