Can somebody suggest an intermediate way to delete all products in magento and reset their table's increment id to 1 without using multiple "truncate" queries found when Googling ?
Magento version ce-1.9.x
to delete all the products, Create a file DeleteProduct.php
inside your magento root folder and write the below code in that file and then execute it with below URL http://www.yourdomain.com/DeleteProduct.php
try the below code :
<?php
require_once('app/Mage.php');
umask(0);
Mage::app('admin');
$productCollection = Mage::getModel('catalog/product')
->getCollection();
foreach($productCollection as $_product)
{
$productID = $_product->getId();
try {
Mage::getModel("catalog/product")->load($productID)->delete(); // this will delete product
} catch (Exception $exception){
var_dump($exception);
die('Exception Thrown');
}
@Manashvi birla
as I said, I also want to reset the product's table auto-increment id to 1 along with deleting products.
Commented
Oct 5, 2015 at 6:53
ALTER TABLE table_name AUTO_INCREMENT = 1;
Commented
Oct 5, 2015 at 7:04