diff --git a/catalog/includes/functions/general.php b/catalog/includes/functions/general.php index f0fc26aa2..a2e416c27 100644 --- a/catalog/includes/functions/general.php +++ b/catalog/includes/functions/general.php @@ -561,6 +561,36 @@ function tep_get_manufacturers($manufacturers_array = '') { return $manufacturers_array; } +//// +// Returns the categories tree as array +// TABLES: categories,categories_description; + function tep_path_tree() { + + $categories_query = tep_db_query("select c.categories_id,c.parent_id,cd.categories_name,c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'"); + + $refs = array(); + $tree = array(); + + while ($categories = tep_db_fetch_array($categories_query)) { + $arr_ref = & $refs[$categories['categories_id']]; + + $arr_ref['id'] = $categories['categories_id']; + $arr_ref['parent_id'] = $categories['parent_id']; + $arr_ref['name'] = $categories['categories_name']; + $arr_ref['image'] = $categories['categories_image']; + + if ($categories['parent_id'] == 0) { + //Root node + $tree[$categories['categories_id']] = & $arr_ref; + } else { + //Children node + $refs[$categories['parent_id']]['children'][$categories['categories_id']] = & $arr_ref; + } + } + unset($arr_ref); + return $tree; + } + //// // Return all subcategory IDs // TABLES: categories