Nachtrag zu meinem Vorschlag aus Antwort #16:
Da es im Backend noch die Einstellung
Konfiguration => Artikel Listen Optionen => "Artikel aus Unterkategorien anzeigen"(= CATEGORIES_SHOW_PRODUCTS_SUBCATS)
gibt und, um die Funktion wirklich variabel zu machen, sollte man die Anzeige der Anzahl der Produkte in einer Kategorie auch von dieser Einstellung abhängig machen und sollte außerdem die Option der Config in Funktions-Parameter wandeln, sodaß die Funktion dann so aussehen könnte:
<?php/**************************************************************************************
* file: nr_count_prods_in_cats.inc.php
* path: /templates/MY_TEMPLATE/source/inc/
* use: replace /inc/xtc_count_products_in_category.inc.php
* which counts in main and in sub-cats linked products muliple times
*
* (c) copyright noRiddle 10-2020
**************************************************************************************/ function nr_count_prods_in_cats
($category_id, $include_inactive = false, $unique_prods = true, $no_sub_cats_count = false) { //BOC config (put this as parameters in function, 27-12-2020, noRiddle) //$unique_prods = true; //true for counting in more than one category linked products only once, else false //$no_sub_cats_count = false; //false for counting also products in sub-catagories, else true //EOC config static
$products_count_array, $products_in_category_array; $active = (($include_inactive === false) ?
0 : 1); if (!is_array($products_count_array)) { $products_count_array = array(); } if (!is_array($products_in_category_array)) { $products_in_category_array = array(); } if(!isset($products_in_category_array[$active])) { $categories_query = xtDBquery
("SELECT p2c.products_id,
p2c.categories_id
FROM ".TABLE_PRODUCTS
." p
JOIN ".TABLE_PRODUCTS_DESCRIPTION
." pd
ON p.products_id = pd.products_id
AND pd.language_id = '".(int
)$_SESSION['languages_id']."'
AND trim(pd.products_name) != ''
JOIN ".TABLE_PRODUCTS_TO_CATEGORIES
." p2c
ON p2c.products_id = p.products_id
WHERE (p.products_status = '1'".(($include_inactive === true) ?
" OR p.products_status = '0'" : '').")
".PRODUCTS_CONDITIONS_P
); if(xtc_db_num_rows
($categories_query, true)) { while ($categories = xtc_db_fetch_array
($categories_query, true)) { $products_in_category_array[$active][$categories['categories_id']][] = $categories['products_id']; } } } if(!isset($products_count_array[$active][$category_id])) { $products_count_array[$active][$category_id] = array(); $products_count_array[$active][$category_id] = ((isset($products_in_category_array[$active][$category_id])) ?
$products_in_category_array[$active][$category_id] : array()); if($no_sub_cats_count === false || ($no_sub_cats_count === true && CATEGORIES_SHOW_PRODUCTS_SUBCATS
== 'true')) { // check sub categories $all_cats_arr = explode(',', check_all_cats
($category_id)); array_shift($all_cats_arr); foreach($all_cats_arr as $sub_cat_id) { $products_count_array[$active][$category_id] = array_merge($products_count_array[$active][$category_id], $products_in_category_array[$active][$sub_cat_id]); } } } if($unique_prods === true || CATEGORIES_SHOW_PRODUCTS_SUBCATS
== 'true') { $products_count_array[$active][$category_id] = array_unique($products_count_array[$active][$category_id]); } return count($products_count_array[$active][$category_id]);}function check_all_cats
($category_id) { $all_cats_str = $category_id; $child_categories_query = xtDBquery
("SELECT c.categories_id
FROM ".TABLE_CATEGORIES
." c
WHERE c.parent_id = ".(int
)$category_id."
".CATEGORIES_CONDITIONS_C
); if(xtc_db_num_rows
($child_categories_query, true)) { while($child_categories = xtc_db_fetch_array
($child_categories_query, true)) { $all_cats_str .= ','.check_all_cats
($child_categories['categories_id']); } } return $all_cats_str;}?> So wird kein Kunden verwirrt durch das was ich in Antwort #16 aufgezählt habe.
Gruß,
noRiddle