The menu block does not count products in subcategories. This can be a major problem, not just because the product counts are wrong. If the parent catalog does not have any products in it, but the children catalogs do, it will not show either the parent catalog or the child catalog.

Ex:
Parent (0)
- Child1 (5)
- Child2 (3)

Should be:
Parent (8)
- Child1 (5)
- Child2 (3)

But instead, nothing is shown.

I have written a simple patch that does checks for each of the children, but there may be a more efficient way to do this rather than doing a new SQL query for every child.

Comments

longwave’s picture

Does your patch take into account three (or more) levels of hierarchy? It looks like it only counts immediate children.

And is this actually a regression from Ubercart 2.x, or did it work the same way as 3.x currently does? (in which case this should be a feature request, not a bug report)

neomenlo’s picture

I haven't tried it on 3 levels of hierarchy, but my understanding is that this function that my patch is inside gets called recursively for every menu item. So, I think it should work no matter how many levels there are.

neomenlo’s picture

StatusFileSize
new1.81 KB

It does not count sub sub categories. You were right, it did not count immediate children.
I have rewritten it so that it now recursively counts all sub categories.

I'm not sure that the new function name is up to Drupal coding standards. I don't know what the rules are, and it's certainly not a well documented function.

giupenni’s picture

+1

silinor’s picture

I use taxonomy_get_children() to get children id`s. And it`s work!

$children = taxonomy_get_children($branch->tid);
  $tids = array($branch->tid);
  foreach ($children as $term){
  	$tids[] = $term->tid;
  } 
  
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', $types)
    ->fieldCondition('taxonomy_catalog', 'tid', $tids, 'IN')
    ->count();
  $num = $query->execute();

Status: Needs review » Needs work

The last submitted patch, countSubcategoriesNEW.patch, failed testing.

longwave’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.