Jump to content

[Resolved] SQL for deleting products from secondary categories


jasehead

Recommended Posts

I have a What's New category - I use this as a secondary category for new products.  I also add (NEW) to the product name.

So I'm at the stage where my What's New category needs a refresh and I want to remove all products from it and start fresh.

First of all, I ran this SQL query to remove the (NEW) from all products:

UPDATE `CubeCart_inventory`
SET `name` = replace(name, ' (NEW)', '')
WHERE `name` LIKE '%(NEW)%'

What I want to know is - can I run this SQL query to remove all products from my What's New secondary category (105), or am I going to do other damage and should instead MANUALLY change every product (about 80+) using Cubecart admin > Products > Categories tab

DELETE FROM `CubeCart_category_index`
WHERE `cat_id` LIKE '105' AND primary LIKE '0'

 

Link to comment
Share on other sites

That DELETE query will certainly work.

I was looking at the effect of deleting the actual category. CubeCart won't let that happen if that category has any sub-categories, or if it has any products assigned to it either as primary or secondary.

 

Link to comment
Share on other sites

My focus was at the product level - just trying to detach the secondary category from 80+ products (not delete the category).  My best guess for secondary categories was the category index table.  If my DELETE query won't leave a trail of severed limbs in CubeCart, great - I'll use it next time.  If this has helped with other issues, also great.

Link to comment
Share on other sites

My research showed that deleting the category would not have happened. (I have made an issue of this in the Github.)

However, if it would have worked, then deleting this category would have freed the associations of all products having this category as a secondary category by securely and assuredly managing the appropriate database queries.

Then, one could quickly reconstruct this category afresh.

Link to comment
Share on other sites

I didn't want to delete the "What's New" category, just empty it.  Using phpMyAdmin to run the SQL would bypass CubeCart having any say about deleting the secondary links in the index - unless it growls at me later.

CubeCart safeguards against deleting a category (using CubeCart admin > Categories) that contains primary products so that there are no orphaned products as a result, but if all products were secondary it should be allowed. I'd still suggest that subcategories be protected - products gone but subcats remain - so the category could only be successfully deleted if no subcats. Much easier to move a few categories than hundreds of products.

I understand that deleting the "What's New" category and reconstructing it would be a quick fix, but I'd have to make sure I didn't make other errors reproducing it.

Anyway, next time I want to clear it out I'll backup the database, run the DELETE query and report back.

Thanks for your time on this ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...