Magento 1.9 – Delete Configurable Products with Associated Products Programmatically

configurable-productdeletemagento-1.9

How can I delete a programmatically created configurable product with it's associate products?

Best Answer

First get the configurable product:

$productId = 100;//change this to what you need
$conf = Mage::getModel('catalog/product')->load($productId);
$productIds = $conf->getTypeInstance()->getUsedProductIds();
//delete the simple products
foreach ($productIds as $id) {
    $product = Mage::getModel('catalog/product')->load($id)->delete();
}
//delete the conf product 
$conf->delete();

I know this is no the fastest way to do it and it uses load in loops but if you don't need to delete hundred of products or you don't need to call this constanlly you should be OK