Closed (fixed)
Project:
Ubercart
Version:
7.x-3.0-rc4
Component:
Catalog
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Apr 2012 at 15:20 UTC
Updated:
19 Mar 2018 at 02:28 UTC
Jump to comment: Most recent
Comments
Comment #1
end user commentedTry here http://www.waldbeek.com/blog/view-taxonomy-term-and-hide-empty-terms and here http://drupal.org/node/1067742
Comment #2
3cwebdev commentedThank you for the information. I have tried these solutions but they only work for the lowest level terms in a tree. It does not function correctly if there is a hierarchy tree structure. In my case, enabling the "content with term" relationship hides all of the catalog terms because there are no products in 1st nest terms.
Example:
Catalog->Top Level Term->Second Level Term->Products
Because the products are several terms deep it will hide all terms.
This issue is compounded when using the catalog block because the block automatically filters out empty terms but the pages do not. Both catalog types should match (like UC2)
I have spent more than several hours working on this but haven't had any luck. Any ideas?
Comment #3
longwaveYou may be better off moving or repeating this question in the Views issue queue, as this is not really specific to Ubercart - any solution would also apply to any taxonomy term listing in Views.
Comment #4
tr commentedComment #6
Jeremy Byrne commentedThis issue is not Fixed. Comment #3 merely suggests seeking a solution elsewhere, even though this is in no way an Issue for the Views module.
After extensive research, and once it had become apparent that there was no simpler way to do it (eg. one which involved no additional Contributed Modules), I created my own solution based on discussion on this thread linked from Comment #1:
This filter will remove all terms which both have no subterms and are associated with no publishedproducts (ie. which are truly "empty categories"). If terms associated with unpublished products are to be included, the INNER JOIN can be removed (ie. all the text from "AS ti" to "AND ti." inclusive, except the WHERE keyword).
Comment #7
TezMan commentedComment #8
TezMan commentedComment #9
TezMan commentedComment #10
tr commentedPlease don't delete the issue summary. If you want to comment on the issue, enter your comments in the "Comment" section.
Comment #11
tr commentedRestored issue summary.
Comment #12
Jeremy Byrne commentedTezMan: Thanks for responding to my suggested fix (even though you inadvertently overwrote the issue). You've indicated an important problem with my suggested filter code (when you say "this filter doesn't remove categories under which subcategories exist under which no (active) nodes exist"), but your suggested change doesn't actually fix that problem, which can really only be addressed using recursive code (because we can't know how far down a hierarchy of productless categories we might have to search before we find a category with a product in it).
Here is my amended solution:
and setting the Filter code to:
Also, after further research, it turns out that the {taxonomy_index} table does not include unpublished nodes, and the Drupal 7 catalog doesn't display unpublished nodes at all. As such, my comment above about adjusting the code to display unpublished nodes should be ignored.
Comment #13
liezie_d commented#12 worked perfectly! many many thanks!!
Comment #14
IanBezanson commentedIf you want to adjust this to account for categories with published items, change the setup code to:
Comment #15
Sigor07 commentedHi, IanBezanson.
I am posting to see if you can help me out.
I have a taxonomy called "Folder" and have nested terms inside and also an Entity Reference field "Assigned to" that takes care of what users have been assigned to a particular node.
I created a taxonomy View using the Views Tree module and also displaying this View in a separate tab belonging to the user profile along with a Views Field View field that shows the content inside the folders (terms).
The code provided previously has worked with showing terms that actually have something in them but now I am trying to show only folders (terms) that both have something AND have been assigned to the current user.
So, if I have "Folder 3" inside of "Folder 1" and "Folder 2", do not show them unless they have content assigned to the current user.
Do you have an idea of what code I could use to achieve this?