Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Possible to delete all products and reset product id’s? 
 
shmk
Sr. Member
 
Total Posts:  297
Joined:  2009-10-28
 
Paulus - 05 September 2011 11:25 AM


Which one exactly? There’s several posted;-)

I’d love to know for 1.5.1.0

And I’m looking for 1.6.0.0

 
Magento Community Magento Community
Magento Community
Magento Community
 
magochdotcom
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2010-10-26
 

Don’t need to execute next sql to delete products:

TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `cataloginventory_stock`;

 
Magento Community Magento Community
Magento Community
Magento Community
 
magochdotcom
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2010-10-26
 

So sql query list :

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;

TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_category_product_index`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE catalog_product_entity;
SET FOREIGN_KEY_CHECKS = 1;

 
Magento Community Magento Community
Magento Community
Magento Community
 
magochdotcom
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2010-10-26
 

Also you can use script delete_byid.php from zip archive delete_byid.zip

1. Deploy your file to new folder ‘magoch’ at the same location with ‘app’ folder on your server.
2. Open project url/magoch/delete_byid.php

Additinal: you can see result file (result_deletedById.csv) passed sku in folder /var/import/ in case you have it before start .
Alternatively you can use it from command line.

Hope it will help for somebody.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sunil rajput
Jr. Member
 
Total Posts:  17
Joined:  2009-04-04
 

How to delete all products in magento
http://www.phptechi.com/how-to-delete-all-products-in-magento.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
daniel5455
Jr. Member
 
Total Posts:  3
Joined:  2011-08-24
 

i ran this query to remove all products from my db

TRUNCATE TABLE `catalog_product_bundle_option`;
    
TRUNCATE TABLE `catalog_product_bundle_option_value`;
    
TRUNCATE TABLE `catalog_product_bundle_selection`;
    
TRUNCATE TABLE `catalog_product_entity_datetime`;
    
TRUNCATE TABLE `catalog_product_entity_decimal`;
    
TRUNCATE TABLE `catalog_product_entity_gallery`;
    
TRUNCATE TABLE `catalog_product_entity_int`;
    
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
    
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
    
TRUNCATE TABLE `catalog_product_entity_text`;
    
TRUNCATE TABLE `catalog_product_entity_tier_price`;
    
TRUNCATE TABLE `catalog_product_entity_varchar`;
    
TRUNCATE TABLE `catalog_product_link`;
    
TRUNCATE TABLE `catalog_product_link_attribute`;
    
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
    
TRUNCATE TABLE `catalog_product_link_attribute_int`;
    
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
    
TRUNCATE TABLE `catalog_product_link_type`;
    
TRUNCATE TABLE `catalog_product_option`;
    
TRUNCATE TABLE `catalog_product_option_price`;
    
TRUNCATE TABLE `catalog_product_option_title`;
    
TRUNCATE TABLE `catalog_product_option_type_price`;
    
TRUNCATE TABLE `catalog_product_option_type_title`;
    
TRUNCATE TABLE `catalog_product_option_type_value`;
    
TRUNCATE TABLE `catalog_product_super_attribute`;
    
TRUNCATE TABLE `catalog_product_super_attribute_label`;
    
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
    
TRUNCATE TABLE `catalog_product_super_link`;
    
TRUNCATE TABLE `catalog_product_enabled_index`;
    
TRUNCATE TABLE `catalog_product_website`;
    
TRUNCATE TABLE `catalog_product_entity`;
     
TRUNCATE TABLE `cataloginventory_stock`;
    
TRUNCATE TABLE `cataloginventory_stock_item`;
    
TRUNCATE TABLE `cataloginventory_stock_status`;
     
INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,\\\'relation\\\'),(2,\\\'bundle\\\'),(3,\\\'super\\\'),(4,\\\'up_sell\\\'),(5,\\\'cross_sell\\\');
    
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,\\\'qty\\\',\\\'decimal\\\'),(2,1,\\\'position\\\',\\\'int\\\'),(3,4,\\\'position\\\',\\\'int\\\'),(4,5,\\\'position\\\',\\\'int\\\'),(6,1,\\\'qty\\\',\\\'decimal\\\'),(7,3,\\\'position\\\',\\\'int\\\'),(8,3,\\\'qty\\\',\\\'decimal\\\');
    
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,\\\'Default\\\');

Now when i try to import the products they dont get assigned the the categories. Its like as if i didnt have the category column in the csv?

any way to fix this? I am using the 1.6.1.0 version.

 
Magento Community Magento Community
Magento Community
Magento Community
 
happyjoylove
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2011-09-28
 

@daniel5455: Try to re-index data after import. Works for me.
Question to all you guys! Is there any way to delete entities using PHP? So I can delete all products using CSV?
Thank You!

 
Magento Community Magento Community
Magento Community
Magento Community
 
codetrio
Jr. Member
 
Total Posts:  3
Joined:  2011-02-13
 

I could not find the SQL queries to run for version 1.7. So I had to find it out from a fresh magento install.
I have added the script in my blog. Check it out here

 
Magento Community Magento Community
Magento Community
Magento Community
 
pherlo
Jr. Member
 
Total Posts:  6
Joined:  2009-12-02
 

This worked great for me running 1.7.0.2

TRUNCATE TABLE `mage_catalog_product_bundle_option`;
TRUNCATE TABLE `mage_catalog_product_bundle_option_value`;
TRUNCATE TABLE `mage_catalog_product_bundle_selection`;
TRUNCATE TABLE `mage_catalog_product_entity_datetime`;
TRUNCATE TABLE `mage_catalog_product_entity_decimal`;
TRUNCATE TABLE `mage_catalog_product_entity_gallery`;
TRUNCATE TABLE `mage_catalog_product_entity_int`;
TRUNCATE TABLE `mage_catalog_product_entity_media_gallery`;
TRUNCATE TABLE `mage_catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `mage_catalog_product_entity_text`;
TRUNCATE TABLE `mage_catalog_product_entity_tier_price`;
TRUNCATE TABLE `mage_catalog_product_entity_varchar`;
TRUNCATE TABLE `mage_catalog_product_link`;
TRUNCATE TABLE `mage_catalog_product_link_attribute`;
TRUNCATE TABLE `mage_catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `mage_catalog_product_link_attribute_int`;
TRUNCATE TABLE `mage_catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `mage_catalog_product_link_type`;
TRUNCATE TABLE `mage_catalog_product_option`;
TRUNCATE TABLE `mage_catalog_product_option_price`;
TRUNCATE TABLE `mage_catalog_product_option_title`;
TRUNCATE TABLE `mage_catalog_product_option_type_price`;
TRUNCATE TABLE `mage_catalog_product_option_type_title`;
TRUNCATE TABLE `mage_catalog_product_option_type_value`;
TRUNCATE TABLE `mage_catalog_product_super_attribute`;
TRUNCATE TABLE `mage_catalog_product_super_attribute_label`;
TRUNCATE TABLE `mage_catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `mage_catalog_product_super_link`;
TRUNCATE TABLE `mage_catalog_product_enabled_index`;
TRUNCATE TABLE `mage_catalog_product_website`;
TRUNCATE TABLE `mage_catalog_product_entity`;
TRUNCATE TABLE `mage_cataloginventory_stock`;
TRUNCATE TABLE `mage_cataloginventory_stock_item`;
TRUNCATE TABLE `mage_cataloginventory_stock_status`;

INSERT INTO `mage_catalog_product_link_typeVALUES(1'relation');
INSERT INTO `mage_catalog_product_link_typeVALUES(3'super');
INSERT INTO `mage_catalog_product_link_typeVALUES(4'up_sell');
INSERT INTO `mage_catalog_product_link_typeVALUES(5'cross_sell');

INSERT INTO `mage_catalog_product_link_attributeVALUES(11'position''int');
INSERT INTO `mage_catalog_product_link_attributeVALUES(23'position''int');
INSERT INTO `mage_catalog_product_link_attributeVALUES(33'qty''decimal');
INSERT INTO `mage_catalog_product_link_attributeVALUES(44'position''int');
INSERT INTO `mage_catalog_product_link_attributeVALUES(55'position''int');

INSERT INTO `mage_cataloginventory_stockVALUES(1'Default');
 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

You can do this from the Admin.

1. Go to Catalog->Manage Products.
2. Click on “Select All”. (this selects ALL products, not just those on the page).
3. From “Actions” dropdown choose “Delete”.
4. Click “Submit”

Voala!

 
Magento Community Magento Community
Magento Community
Magento Community
 
winzter143
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2011-04-04
 
Sam Figueroa - 29 September 2009 05:48 AM

I think while this will be a whole lot slower it is more future-version-proof-ish since it works against the API.
Works for me.

function deleteAllProducts()
  
{
    $products 
Mage::getResourceModel('catalog/product_collection')->setStoreId(STORE_ID)->getAllIds();
    if(
is_array($products))
    
{
      
foreach ($products as $key => $productId)
      
{
        
try {
          $product 
Mage::getSingleton('catalog/product')->load($productId);
          
Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product));
          
$product->delete();          
        
catch (Exception $e{
          
echo "<br/>Can't delete product w/ id: $productId";
        
}
      } 
    }
  }

Just bit question what this code do in deletion?

Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product));

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
mbyrne
Jr. Member
 
Total Posts:  5
Joined:  2010-10-09
 

When I needed to clear out all categories in Magento 1.7.0.2 I used the suggestions above but tweaked slightly. TRUNCATE was complaining about foreign key references so I just ran DELETE and then reset the AUTOINCREMENT so it started back at 3.

DELETE FROM `catalog_category_entity`;
DELETE FROM `catalog_category_entity_datetime`;
DELETE FROM `catalog_category_entity_decimal`;
DELETE FROM `catalog_category_entity_int`;
DELETE FROM `catalog_category_entity_text`;
DELETE FROM `catalog_category_entity_varchar`;
DELETE FROM `catalog_category_product`;
DELETE FROM `catalog_category_product_index`;

insert  into `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`position`,`level`,`children_count`) values (1,3,0,0,NOW(),NOW(),'1',1,0,1),(2,3,3,0,NOW(),NOW(),'1/2',1,1,0);
insert  into `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) values (1,3,32,0,2,1),(2,3,32,1,2,1);
insert  into `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) values (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');

ALTER TABLE catalog_category_entity AUTO_INCREMENT 3;

Did the job for me. Hope it helps others.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mpw5013
Jr. Member
 
Total Posts:  13
Joined:  2010-11-10
 

Don’t forget the Cache Flat Tables and honestly, leave catalog_product_link_type alone if you don’t need to truncate it… I removed it and added the flat tables ...

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_flat_1`;
TRUNCATE TABLE `catalog_product_flat_2`;
TRUNCATE TABLE `catalog_product_flat_3`;
TRUNCATE TABLE `catalog_product_flat_4`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_category_product_index`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE catalog_product_entity;
SET FOREIGN_KEY_CHECKS = 1;

 
Magento Community Magento Community
Magento Community
Magento Community
 
jrp1
Sr. Member
 
Total Posts:  143
Joined:  2011-04-17
 

Mike Smullin solution worked fantastic for me.

Just had to add that it was ok for the foreign key to be constrained for the time being.

at the top of his code put the following if you’re having foreign key problems

SET FOREIGN_KEY_CHECKS=0;

and at the bottom of his code but the following to turn it back on

SET FOREIGN_KEY_CHECKS=1;

Hope I was able to help with those having foreign key problems.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oliverjn
Jr. Member
 
Total Posts:  29
Joined:  2012-11-28
 

The ultimate erazzzer script running on our /Magento CE 1.7.0.2!!1

SET FOREIGN_KEY_CHECKS 0
 
TRUNCATE TABLE `catalog_product_bundle_price_index`; 
TRUNCATE TABLE `catalog_product_bundle_selection`; 
TRUNCATE TABLE `catalog_product_bundle_selection_price`; 
TRUNCATE TABLE `catalog_product_bundle_option_value`; 
TRUNCATE TABLE `catalog_product_bundle_option`; 
TRUNCATE TABLE `catalog_product_entity_datetime`; 
TRUNCATE TABLE `catalog_product_entity_decimal`; 
TRUNCATE TABLE `catalog_product_entity_gallery`; 
truncate table `catalog_product_entity_group_price`; 
TRUNCATE TABLE `catalog_product_entity_int`; 
TRUNCATE TABLE `catalog_product_entity_media_gallery`; 
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`; 
TRUNCATE TABLE `catalog_product_entity_text`; 
TRUNCATE TABLE `catalog_product_entity_tier_price`; 
TRUNCATE TABLE `catalog_product_entity_varchar`; 
TRUNCATE TABLE `catalog_product_flat_1`; 
TRUNCATE TABLE `catalog_product_flat_2`; 
TRUNCATE TABLE `catalog_product_flat_3`; 
TRUNCATE TABLE `catalog_product_flat_4`; 
TRUNCATE TABLE `catalog_product_link`; 
TRUNCATE TABLE `catalog_product_link_attribute_decimal`; 
TRUNCATE TABLE `catalog_product_link_attribute_int`; 
TRUNCATE TABLE `catalog_product_link_attribute_varchar`; 
TRUNCATE TABLE `catalog_product_option`; 
TRUNCATE TABLE `catalog_product_option_price`; 
TRUNCATE TABLE `catalog_product_option_title`; 
TRUNCATE TABLE `catalog_product_option_type_price`; 
TRUNCATE TABLE `catalog_product_option_type_title`; 
TRUNCATE TABLE `catalog_product_option_type_value`; 
TRUNCATE TABLE `catalog_product_super_attribute_label`; 
TRUNCATE TABLE `catalog_product_super_attribute_pricing`; 
TRUNCATE TABLE `catalog_product_super_attribute`; 
TRUNCATE TABLE `catalog_product_super_link`; 
TRUNCATE TABLE `catalog_product_enabled_index`; 
TRUNCATE TABLE `catalog_product_website`; 
TRUNCATE TABLE `catalog_category_product_index`; 
 
TRUNCATE TABLE `catalog_category_product`; 
 
TRUNCATE TABLE `catalog_product_entity`; 
truncate table `catalog_product_relation`; 

TRUNCATE TABLE `cataloginventory_stock_item`; 
TRUNCATE TABLE `cataloginventory_stock_status`; 
SET FOREIGN_KEY_CHECKS 1;
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top