deleting all products but not Categories.

Hi you all.



how can i delete all products but not my categories?



it seams to me that it is not optimal i have to delete my categories.



is there a way around this? i have about 52k and it will take to long to delete 500 at a time. so if there is a quick way pleas lat me know

With that many products to delete, I'd just delete all the product related data from the database. Or you could set the products page in admin to display 1000 at a time and try delete them all that way, still it's going to take a while doing that 52 times and waiting for the page to load with 1000 products on it each time.

You can delete all products by adding

```php
/*****************************************************************

*****************************************************************/



if ( !defined('AREA') ) { die('Access denied'); }



if($mode=='delete_all_products'){

$products = db_get_array('SELECT product_id FROM ?:products');

foreach($products as $p){

fn_delete_product($p['product_id']);

}



fn_set_notification('N', fn_get_lang_var('notice'), 'All the products has been deleted with succes!');

return array(CONTROLLER_STATUS_OK, “products.manage”);

}

?>

```

into /addons/my_changes/controllers/admin/my_changes.php, if the folders or file are missing you need to create them.



After adding the code in the right place you just need to access the link http://www.your_domain.com/admin.php?dispatch=my_changes.delete_all_products



If you rename admin.php you replace with your own, link can be accessed only from admin.



My Advice: After you delete the products please add this secure code [color=#ff0000]exit;[/color]


...
if($mode=='delete_all_products'){
exit;
...


for you not to be able to delete products by mistake in the future, and when you wish to delete them again just comment the exit like this


...
if($mode=='delete_all_products'){
//exit;
...


and access the link above.





I hope that helps,





Valentin

Hi just to be shure is it /addons/my_changes/controllers/admin/my_changes.php or skin/myskin/admin/addons/my_changes/controllers/admin/my_changes.php



I cant accualy test it before i am reday to delete all :o)



Thanks m8

This is not a skin file ;) , the address is correct.

How do you wish to test it ? :D





Valentin

Thanks then i dit it the right way :grin:



but i added the exit option and i get error 404 page not found. i will test it this weekend or maby ill set up a test server and test it there first.





thanks again m8

enjoy

This was a VERY helful piece of code. Thanks Vali. Worked for me on cscart Ultimate.

@swimcommunications

Glad to hear it





Valentin

When running this option to delete products will it also delete all the product images? We have had issues in the past trying to delete products to do a re-import and the old images were still on the FTP server in folders under product images. Then when re-importing products products would have the wrong images almost as if part of the database thought there shouldn't be any product images but then the component importing the images was logging the new images as product image # 587 rather than #1. Basically we are wanting a way to clear out all products, and then clear out all product images, both from the database and the FTP server, and get the cart products and associated images back to as if we cleared out everything and started from scratch. Any help is appreciated

@jmarshall

fn_delete_product($product_id) is function used by cs-cart to delete a product, it's deleting anything is related to the product (images, features, options … ) and hooks related to this action used into any custom addon





Valentin

[quote name='Vali' timestamp='1360224051' post='154649']

You can delete all products by adding

```php
/*****************************************************************

*****************************************************************/



if ( !defined('AREA') ) { die('Access denied'); }



if($mode=='delete_all_products'){

$products = db_get_array('SELECT product_id FROM ?:products');

foreach($products as $p){

fn_delete_product($p['product_id']);

}



fn_set_notification('N', fn_get_lang_var('notice'), 'All the products has been deleted with succes!');

return array(CONTROLLER_STATUS_OK, “products.manage”);

}

?>

```

into /addons/my_changes/controllers/admin/my_changes.php, if the folders or file are missing you need to create them.



After adding the code in the right place you just need to access the link http://www.your_doma…te_all_products



If you rename admin.php you replace with your own, link can be accessed only from admin.



My Advice: After you delete the products please add this secure code [color=#ff0000]exit;[/color]


...
if($mode=='delete_all_products'){
exit;
...


for you not to be able to delete products by mistake in the future, and when you wish to delete them again just comment the exit like this


...
if($mode=='delete_all_products'){
//exit;
...


and access the link above.





I hope that helps,





Valentin

[/quote]



Hello how can i adapt it in cs-cart 4.1.4 , i want to use a csv file to delete some products, around 200 products

[quote name='Vali' timestamp='1360224051' post='154649']

You can delete all products by adding

```php
/*****************************************************************

*****************************************************************/



if ( !defined('AREA') ) { die('Access denied'); }



if($mode=='delete_all_products'){

$products = db_get_array('SELECT product_id FROM ?:products');

foreach($products as $p){

fn_delete_product($p['product_id']);

}



fn_set_notification('N', fn_get_lang_var('notice'), 'All the products has been deleted with succes!');

return array(CONTROLLER_STATUS_OK, “products.manage”);

}

?>

```

into /addons/my_changes/controllers/admin/my_changes.php, if the folders or file are missing you need to create them.



After adding the code in the right place you just need to access the link http://www.your_doma…te_all_products



If you rename admin.php you replace with your own, link can be accessed only from admin.



My Advice: After you delete the products please add this secure code [color=#ff0000]exit;[/color]


...
if($mode=='delete_all_products'){
exit;
...


for you not to be able to delete products by mistake in the future, and when you wish to delete them again just comment the exit like this


...
if($mode=='delete_all_products'){
//exit;
...


and access the link above.





I hope that helps,





Valentin

[/quote]



What version of CS-Cart does this work for? I have 4.1.5 and I did as you said (created a file at /app/addons/my_changes/controllers/admin/my_changes.php) but nothing happens and I get a 404 error.

Hi, is this also working for 4.2.1? thx.

Hi, Is this posible to set this link in de admin product_view as extra item? gr.

[quote name=‘pholcomb’ timestamp=‘1407178162’ post=‘188803’]

What version of CS-Cart does this work for? I have 4.1.5 and I did as you said (created a file at /app/addons/my_changes/controllers/admin/my_changes.php) but nothing happens and I get a 404 error.

[/quote]



Please check if My Changes add-on is active ;)

[quote name='pholcomb' timestamp='1407178162' post='188803']

What version of CS-Cart does this work for? I have 4.1.5 and I did as you said (created a file at /app/addons/my_changes/controllers/admin/my_changes.php) but nothing happens and I get a 404 error.

[/quote]



Correct path is app/addons/my_changes/controllers/[color=#ff0000]backend[/color]/my_changes.php



Please try

Hi,

I have change the dir. to backend and delete the admin dir. butt still not work(404).

Is it posible to make this a item in popdown_selection products?



gr.

[quote name='richardfmm' timestamp='1408626208' post='190194']

Hi,

I have change the dir. to backend and delete the admin dir. butt still not work(404).

Is it posible to make this a item in popdown_selection products?



gr.

[/quote]



Hm… It works for me. Make sure that the My changes add-on in installed and activated.



Please also attach the image again

Hi,

i have try this: www.domain/public_html/cs4/admin.php?dispatch=my_changes.delete_all_products

and www.domain/public_html/cs4/app/addons/my_changes/controlers/backend/my_changes.php



Bott i get a 404.