Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Is there any way to delete multiple products by filtering with SKU? I have around 1000 products that I want to delete.

share|improve this question

3 Answers 3

Kevin S, you can delete product by csv file. Just follow the billow step

Step 1 :

Create a csv file and past the skus which you want to delete from system. Give the file name as skus.csv

Step 2 :

Create & replace a php file in your root directory. Then past the following code

require_once '../app/Mage.php';
Mage :: app("default") -> setCurrentStore( Mage_Core_Model_App :: ADMIN_STORE_ID );
$skuAll =array();
$file_handle = fopen("skus.csv", "r");
 while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);
$allSku = $line_of_text[0];

}
$products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter(
        'sku', array('in' => $allSku)
    )
    ->load();

    if(is_array($products))
    {
        foreach ($products as $key => $pId)
        {
            try
            {
                $product = Mage::getModel('catalog/product')->load($pId)->delete();
                echo "successfully deleted product with ID: ". $pId ."<br />";
            } 
            catch (Exception $e) 
            {
                echo "Could not delete product with ID: ". $pId ."<br />";
            }
        }
    }

Note : I recommended to you before run this code you must get the backup. I hope its will be help you.

share|improve this answer

The fastest way to do it is to run this query directly.

DELETE FROM `catalog_product_entity` WHERE `sku` IN ('SKU1', 'SKU2', ...., 'SKU1000');

Everything should cascade nicely. attribute values will be deleted, category relations will be deleted, upsells, crosssells and related and so on.

share|improve this answer
2  
dont forget to reindex after this (if you use flat product catalog) –  Vladimir Kerkhoff Jun 29 at 6:43

The none code way

In the admin section under Manage Products would will find a grid with all your products. There is a column called SKU. Here you can filter your products based on the value.

sku filter

Then once you have filtered by SKU you can use the checkboxes on the left hand side to select all the items you wish to delete.

multiple select

Notice the select all which will select all items in the complete grid and select visible which will only select items on the current page of the grid.

Once you have selected the items you want you can use the mass action button on the top right hand side of the grid and select the delete option.

delete mass action

This will prompt you to make sure you a sure you want to delete these items. After selecting yes to this pop-up it will proceed to delete your items. Depending on your index settings you may have to run a re-index after this process.

share|improve this answer
    
And Select All works with terrifying efficiency. Accidentally choosing it without any sort of search constraints truly deletes everything in your product catalog, and once started, killing the server or running out of memory during the delete are the only things that stop it. –  Fiasco Labs Jun 29 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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