cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting ALL products from Magento 2

Deleting ALL products from Magento 2

Having some trouble deleting products that were imported. Have about 10,000 products that I want to remove in bulk. Can't seem to get the right command to run on the SSH. 

Any help?

Thanks

3 REPLIES 3

Re: Deleting ALL products from Magento 2

Hi @allen_groff,

 

you can delete from the database as well using following query. 

delete from catalog_product_entity;

But It will delete all the products from the magento.

If you want to delete specific products then you can use where condition as well.

delete from catalog_product_entity where entity_id = ? ;

I hope it will help you!
 

Re: Deleting ALL products from Magento 2

Hi,

 

Deleted about 52 files from VAR filezilla folder and the website template just vanished.. Need some assistance.

 

 

Re: Deleting ALL products from Magento 2

Please follow the below to resolve this

 

By script to delete products, to delete all products then you need to load products collection and delete products
Below is script to delete product.

 

 

$objectManager->get('Magento\Framework\Registry')->register('isSecureArea', true);
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()->addAttributeToSelect('*')->load();
$app_state = $objectManager->get('\Magento\Framework\App\State');
$app_state->setAreaCode('frontend');

foreach ($collection as $product){
   try {
           echo 'Deleted : '.$product->getName()."<br>";
           $product->delete();

       } catch (Exception $e) {
           echo 'Unable to delete product : '.$product->getName()."<br>";
           echo $e->getMessage()."<br>";
    }
}

 

 

Let me know if any issues


If my answer is useful, please Accept as Solution & give Kudos