Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In UC6, if a catalog category existed but did not contain any products it would not be displayed. Is this possible un UC7? I am very familiar with Views but I can't see a way to set it to not display a category term if not products exist within it's hierarchy.
To complicate matters, our categories are hierarchical and may be several levels deep. So we would need a way to check through each level to see if there are any products in it and, if not, not display the top highest level category which does not have products in its children.
Possible?
Comments
Comment #1
end user CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: TR commentedComment #6
Jeremy Byrne CreditAttribution: Jeremy Byrne at Upgrade Ubercart 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 CreditAttribution: TezMan as a volunteer commentedComment #8
TezMan CreditAttribution: TezMan as a volunteer commentedComment #9
TezMan CreditAttribution: TezMan as a volunteer commentedComment #10
TR CreditAttribution: 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 CreditAttribution: TR commentedRestored issue summary.
Comment #12
Jeremy Byrne CreditAttribution: Jeremy Byrne at Upgrade Ubercart 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 CreditAttribution: liezie_D commented#12 worked perfectly! many many thanks!!
Comment #14
IanBezanson CreditAttribution: IanBezanson commentedIf you want to adjust this to account for categories with published items, change the setup code to:
Comment #15
Sigor07 CreditAttribution: 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?