I'm using a using a custom function to display child nodes of a taxonomy term while displaying the term page. Here is the function
function theme_name_child_terms($vid = 1) {
if(arg(0) == 'taxonomy' && arg(1) == 'term') {
$children = taxonomy_get_children(arg(2), $vid);
if(!$children) {
$custom_parent = taxonomy_get_parents(arg(2));
$parent_tree = array();
foreach ($custom_parent as $custom_child => $key) {
$parent_tree = taxonomy_get_tree($vid, $key->tid);
}
$children = $parent_tree;
}
$output = '<ul>';
// Avoid unnecessary "Invalid foreach" errors showing up in the log:
if (!empty($children)) {
// If not empty, run the foreach loop:
foreach ($children as $term) {
// Then check to see if any nodes exist for that term id:
$number_of_nodes = taxonomy_term_count_nodes($term->tid);
// If there ARE nodes...
if ($number_of_nodes > 0) {
// ... then add them to the output:
$output .= '<li>';
$output .= l($term->name . ' (' . $number_of_nodes . ')', 'taxonomy/term/' . $term->tid);
$output .= '</li>';
}
}
}
$output .= '</ul>';
return $output;
}
}
This is the output: screen shot. You can can see that it's showing terms and node counts in brackets for items that are not in the 'jewellery' catalogue anymore as they are sold.
The problem I have is that the nodes i'm dealing with are products in an ubercart catalogue - - all items are unique as it's an antique trading site. The function above still counts 'sold' items as nodes associated with the term - a sold item is of course still tagged with a taxonomy term . - so, some terms are leading to blank pages, because I filter out nodes that are sold, from the taxonomy view.
Can another step be added to the function that checks each node associated with a term if it is a has stock level of 1 or above?
I've found the following function in uc_stock.module:
/**
* Get the stock level of a particular product SKU.
*
* @param $sku
* The Ubercart product SKU of the stock level to return.
* @return:
* The SKU's stock level, or FALSE if not active.
*/
function uc_stock_level($sku) {
$stock = db_fetch_object(db_query("SELECT active, stock FROM {uc_product_stock} WHERE sku = '%s'", $sku));
if ($stock && $stock->active) {
return $stock->stock;
}
return FALSE;
}
I just can't figure out where or how to call this function in the original function. It needs to be passed the product 'sku', but i'm not sure how to give it that parameter. I guess it should be something like:
$stock = uc_stock_level($sku);
if ($stock > 0) {
...
}
Any help much appreciated.