There are a lot of posts regarding this issue on Magento. Most of them work but the problem with Categories not resetting their values to ZERO after executing the delete codes/SQL statements still persists and not being addressed up until now.
Does anyone here has the correct code or procedure to properly delete all products from the inventory and have the Category listing also reset to zero after executing it?
Thanks in advance.
Find & Remove Unused Product Images in Magento 2 To clean unused product images in Magento 2, go to Image Clean > Unused Product Images. The backend grid – 'Unused Product Images' lists all the product images in the Magento 2 store that are not being used by any of the products.
In an stand alone script:
<?php
require 'app/Mage.php';
Mage::app('admin')->setUseSessionInUrl(false);
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
try {
$product->delete();
} catch(Exception $e) {
echo "Product #".$product->getId()." could not be remvoved: ".$e->getMessage();
}
}
Did that for more that 1400 products, worked fine. You have to do a reindexing after that.
Beware the above script will delete ALL your products
Deleting all products from Magento can be easily achieved, just run:
DELETE FROM `catalog_product_entity`
Because of the foreign key constraints set up in Magento's database, all other tables that have product information in them are cleaned up nicely. It will of course take some time to delete a lot of products, but it at least gets cleaned up nicely.
If the query can't run because of maximum execution time, you can always run something like:
DELETE FROM `catalog_product_entity` LIMIT 10000
Update: this logic also gets used in Magento's core, so it's safe to use! https://github.com/OpenMage/magento-mirror/blob/magento-1.8/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php#L462
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With