Categories
Magento

Magento – Programmatically Load and Delete Products

[php]
<?php
// Register a secure admin environment
Mage::register(‘isSecureArea’, 1);

// Load the Magento product by entity_id
$product = Mage::getModel(‘catalog/product’)->load($productId);
// Load the Magento product by sku
$product = Mage::getModel(‘catalog/product’)->loadByAttribute(‘sku’, $productSku);
// Load the Magento product by name
$product = Mage::getModel(‘catalog/product’)->loadByAttribute(‘name’, $productName);

// Delete the product
$product->delete();
?>
[/php]

5 replies on “Magento – Programmatically Load and Delete Products”

Fatal error: Call to a member function getModelInstance() on a non-object in dont work..

Mage::register(‘isSecureArea’, 1);
$productId=1577;
$product = Mage::getModel(‘catalog/product’)->load($productId);
$product->delete();

Comments are closed.