how to delete all unavailable items quickly?

Hello!



I need advice for this. I have a script that updates my catalog every 24 h, it is a large catalog with nearly 20 000 items. The problem is that items out of stock are left as “unavailable” but not deleted, so after a few months i have nearly 15 000 items that will not be in stock ever again and i need to delete them as they’re taking up space. Deleting all these items manually is a headache plus it gives me an error message when i try to delete too many in one click at admin.

is there a simple way to delete all unavailable items in my store with one order? maybe a mysql query or something



Please, let me know

can anyone help? is there a query in the db that can delete all unavailable products with a click?

Product information is stored in more than 1 table i.e. images and images links. It would be best to delete from admin so that all of the info is removed.



What kind of error are you getting when mass deleting from admin?

[quote name=‘mirnitagl’]can anyone help? is there a query in the db that can delete all unavailable products with a click?[/QUOTE]



This will delete all products that have a ‘disabled’ status. Please backup your database before using this. (it’s untested).



Put this code in a controller and add your own extension to a dispatch

ex) dispatch=products.deletedisabled



then just load the page to execute it.



$a = db_get_array("SELECT product_id FROM ?:products WHERE status = 'D'");
foreach($a as $v){
fn_delete_product($v['product_id']);
}

I am tired of saying cs-cart team i do not get notification messages for new posts, though I have set it so. I had not seen these replies until now.



Thank you very much for answering me.



Tool Outfitters, when mass deleting I get a “page not found error” and it always leads me to the store home page, which is weird, 'cause it is not even admin home page.



twin892, thanks for the tip, I’ll try it taking all precautions

twin892, i made a site full backup and contacted a friend to help me do what you advised, yet neither he nor me know what you mean by a controller.

Please, could you explain to me (as if i were a 5-year-old baby) this part:



Put this code in a controller and add your own extension to a dispatch

ex) dispatch=products.deletedisabled



isn’t better to run this code in a mysql query?



here it is what i did, i created a php file and named it deleteunavailable.php. I wrote there the code :




$a = db_get_array("SELECT product_id FROM ?:products WHERE status = 'D'");
foreach($a as $v){
fn_delete_product($v['product_id']);
}






Then load it. I get an error message: “page not found” in my store home page. The same thing again.

Sorry I was a little unclear. open up



controllers → admin → products.php



before this line


// ---------------------------------------------------- Related functions --------------------------------



add



if($mode == "deletedisabled"){
$a = db_get_array("SELECT product_id FROM ?:products WHERE status = 'D'");
foreach($a as $v){
fn_delete_product($v['product_id']);
}
}




then go to the directory



skins → [skin] → admin → views → products



and add a file called “deletedisabled.tpl”



now you can go to example.com/admin.php?dispatch=products.deletedisabled



and it will perform the maintenance

twin892, thank you for replying.



I am having some trouble following your instructions, which are now very clear and I think that is because i forgot to mention I am using 1.3.5 sp4 version. My fault!



Instead of controllers,etc. I used :

include → admin → products.php and copied there what you advised.



Then I went to skins → [skin] → admin → views → products but I see no “views” folder. where must I go in 1.3.5 sp4 ?



Thanks in advance.