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.

user2045
  • 831
  • 3
  • 16
  • 29
Netorica
  • 471
  • 1
  • 7
  • 24

3 Answers3

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');
Marius
  • 197,939
  • 53
  • 422
  • 830
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('test@test.com');
$customer->setIsDeleteable(true);
$customer->delete();
Netorica
  • 471
  • 1
  • 7
  • 24
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();
AreDubya
  • 1,344
  • 1
  • 12
  • 25
Hassan Ali Shahzad
  • 2,330
  • 18
  • 35