Unpublish Categories with No Products?

  • Posts: 60
  • Thank you received: 3
10 years 10 months ago #175368

-- HikaShop version -- : 2.3.3
-- Joomla version -- : 3.3.6

Is there a way to automatically un-publish any categories that don't have a product associated with it? If not, is there a query that would do it?

I understand that it's possible to not show that category, but I'm using a third party menu structure that creates a menu item for any published category.

[EDIT]
To clarify:
• hikashop_product_category - shows the product_id and the category_id together in one table
• hikashop_category - shows the full list of category_id rows

So the query would accomplish the following:
IF a category from hikashop_category DOES NOT have a product_id associated with it in hikashop_product_category then SET hikashop_category.category_published to 0

If this could be done in a Mass Action, all the better!
[/EDIT]

Thanks for your help!

Last edit: 10 years 10 months ago by blueagle1829. Reason: Clarification

Please Log in or Create an account to join the conversation.

  • Posts: 84301
  • Thank you received: 13697
  • MODERATOR
10 years 10 months ago #175385

There is no option for that since we have an option to not show the categories in that case on category listings generated by HikaShop.
The best would be that if it's another extension which generates your menu structure, that it monitor the products and change the published state of the menu items when the categories have no available products.

Otherwise, it can be done manually with two SQL queries:
SELECT a.category_id FROM #__hikashop_category as A LEFT JOIN #__hikashop_product_category AS b ON a.category_id=b.category_id WHERE b.category_id IS NULL;
will give you the category_id of each category without a product.
UPDATE #__hikashop_category SET category_published=0 WHERE category_id IN (XXX, YYY, ZZZ)
wil disable all the categories with their category_id being XXX, YYY, ZZZ that you got as a result of the first query.

The following user(s) said Thank You: blueagle1829

Please Log in or Create an account to join the conversation.

  • Posts: 60
  • Thank you received: 3
10 years 10 months ago #175814

Thanks, Nicolas!

As a follow-up, I think there is a way to combine that into one query, for anyone who runs across this thread in the future... Nicolas, please correct me if there's any reason this won't work.

UPDATE #__hikashop_category hc SET category_published = 0 WHERE (SELECT COUNT(product_id) FROM #__hikashop_product_category hpc WHERE hpc.category_id = hc.category_id) < 1

Thanks again for your help!

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum