Ja, das ist ein Bug, wenn man so will (könnte man auch anders sehen).
Es liegt an der Funktion
xtc_count_products_in_category() in
/inc/xtc_count_products_in_category.inc.php die zum Zählen der Produkte benutzt wird.
Mache dazu bitte
ein Ticket auf.
Ich denke, daß auch die Rekursion in der genannten Funktion nicht nötig ist weil bereits alle Kategorien, auch Sub-Kategorien, nach der ersten Query im Array
$products_in_category_array vorhanden sind.
Löung für dich könnte sein:
Erstelle eine eigene Datei als Kopie der genannten Funktion und lege sie in
/templates/DEIN_TEMPLATE/source/inc/.
Benenne die Datei und die Funktion allerdings um, z.B.
custom_count_prods_in_cats() bzw.
custom_count_prods_in_cats.inc.php und ändere sie wie folgt:
<?php/**************************************************************************************
* file: custom_count_prods_in_cats.inc.php
* path: /templates/MY_TEMPLATE/source/inc/
* use: replace /inc/xtc_count_products_in_category.inc.php
* which is buggy and counts in main and in sub-cats linked products muliple times
*
* (c) copyright GTB, reworked by noRiddle 10-2020
**************************************************************************************/ function custom_count_prods_in_cats
($category_id, $include_inactive = false) { 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()); // check sub categories $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)) { $products_count_array[$active][$category_id] = array_merge($products_count_array[$active][$category_id], $products_in_category_array[$active][$child_categories['categories_id']]); } } } $products_count_array[$active][$category_id] = array_unique($products_count_array[$active][$category_id]); return count($products_count_array[$active][$category_id]); }?> Außerdem mußt du dann in
/templates/DEIN_TEMPLATE/inc/xtc_show_category.inc.php das
$products_in_category = xtc_count_products_in_category($counter);
hiermit ersetzen
//$products_in_category = xtc_count_products_in_category($counter);
$products_in_category = custom_count_prods_in_cats($counter); //use my own function, 10-2020, DEIN_KÜRZEL
und in
/templates/DEIN_TEMPLATE/source/boxes/categories.php das
require_once (DIR_FS_INC.'xtc_count_products_in_category.inc.php');
hiermit ersetzen
//require_once (DIR_FS_INC.'xtc_count_products_in_category.inc.php');
require_once (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/inc/custom_count_prods_in_cats.inc.php'); //use my own function, 10-2020, DEIN_KÜRZEL
Die von mir gepostete neue Funktion vermeidet die Rekurison (weniger Funktionsaufrufe und somit Queries) und zählt in Sub-Kategorien verlinkte Produkte die sich auch in der Hauptkategorie befinden nicht doppelt. Sie kann jedoch evtl. noch weiter optimiert werden. Vielleicht schaut noch jemand darauf ?
Gruß,
noRiddle
*NACHTRAG*
Ich sehe gerade, daß das so auch noch nicht ganz okay ist. Für die Hauptkategorien ist es okay, nicht jedoch für Unterkategorien. Schaue mir das später nochmals an...