Can deleting a category delete products?

I have a bad feeling I already know the answer to this question, but need to confirm.



I recently transferred a catalog from zen to cs-cart and set about combining categories.



My assumption was that if you delete a category that has products under it, that the products would be essentially orphaned.



But now that I am going through trying to put products in their respective categories there are bunch of items I cannot find.



So - my question simply is - if you delete a category can that action potentially delete products too?

I’m afraid you’re right. I accidentally deleted a category recently and all the products I had under that category also got deleted with it.



I was lucky enough that my hosting company was able to restore the deleted category, including all the missing products.

Wow. No warning about that. Now i’m really burnt…



Not sure whether to pay for the migration again and start from scratch or try and add the dozens of products manually :frowning:

Definitely my bad for not backing up the DB before I did anything

A practice that can help is to have a hidden category called All Products. Every product has a secondary category of All Products in addition to any normal secondary categories.

That sounds like a fantastic idea… Why didn’t I think of that??



I’m going to set up a hidden category for all my products before I do anything else.

[quote name=‘tbirnseth’]A practice that can help is to have a hidden category called All Products. Every product has a secondary category of All Products in addition to any normal secondary categories.[/QUOTE]



Nice idea… but didn’t work. It deleted them from all categories. sigh…

[quote]

Nice idea… but didn’t work. It deleted them from all categories. sigh…

[/quote]

Hmm… Not from what I’ve seen…



If I have product_id 123 in both CatA and CatB and then delete CatA, product_id 123 remains but is only in CatB

Why in the world does CS-Cart do this? It doesn't make any sense at all… clearly if I wanted to delete a product, I'd delete the Product… I wouldn't delete a category



At the very least there should be a warning – “WARNING: This category contains X products which will be deleted permanently. Do you want to continue?”

It has no idea how many of those products are ONLY in that category. To determine it would take far too much time/resources.

It only deletes the product if that is the last reference to the product (I.e. the product ONLY resides in that category).



If it didn't delete the product, what category do you think it would be associated with?



All products have to be associated with at least one category. That's why I recommend a hidden category named 'all products' so that all products are always contained in that category and won't be zapped if/when you delete another category.

When I delete a category it seems to delete all the products even if they are also in a secondary category.. Is there any new update on this topic?

it shouldn't delete products that are in other categories.

it shouldn't delete products that are in other categories.

If the current category is main for the product, it will be deleted

If the current category is secondary for the product, it will not be deleted

When I delete a category it seems to delete all the products even if they are also in a secondary category. Is there any new update on this topic?


Starting with CS-Cart 4.3.5, products aren't deleted automatically, but put into a special category instead: http://docs.cs-cart.com/4.4.x/user_guide/manage_products/categories/trash_category.html Please note that it doesn't apply to Multi-Vendor.

I do not see the Trash category in my dashboard.. I have Multi Vendor 4.3.9

I do not see the Trash category in my dashboard. I have Multi Vendor 4.3.9


I'm sorry for a possible misunderstanding. Indeed, the trash category exists only in CS-Cart, not in Multi-Vendor. You can delete a category on our demo websites to compare the behavior:
http://demo.cs-cart.com/
http://demo.mv.cs-cart.com/

I've updated my answer above, and I'll add a warning to the documentation as well.

I see, do you have any advice for multi vendor store owners?

I see, do you have any advice for multi vendor store owners?

You can create small modification, which will check if a product is assigned to several categories. If yes, it will not be deleted and corresponding notification will be displayed to the administrator

Use the delete_product_pre hook in the fn_delete_product function (app/functions/fn.catalog.php)

You can create small modification, which will check if a product is assigned to several categories. If yes, it will not be deleted and corresponding notification will be displayed to the administrator

Use the delete_product_pre hook in the fn_delete_product function (app/functions/fn.catalog.php)

Is there a module or plugin for this? I am not tech savy to create that hook.. or do you have any advice on who can do this for me for a small fee?

Is there a module or plugin for this? I am not tech savy to create that hook.. or do you have any advice on who can do this for me for a small fee?

Here is the solution :

- activate the My changes module

- create the app/addons/my_changes/init.php file

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

fn_register_hooks(
‘delete_product_pre’
);

- create the app/addons/my_changes/func.php file

use Tygh\Registry;

if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }

function fn_my_changes_delete_product_pre($product_id, &$status)
{
$categories_count = db_get_field(“SELECT COUNT(category_id) FROM ?:products_categories WHERE product_id = ?i”, $product_id);
if ($categories_count > 1) {
$status = false;
fn_set_notification(‘E’, __(‘error’), __(‘product_not_deleted’));
}
}

- create the product_not_deleted language variable on the Administration -> Languages -> Translations page

- check the result

(!) Not tested