suhy Posted April 7, 2007 Posted April 7, 2007 Hi, Need some help as I used all my resources and I'm all lost .... When I turn "Show category counts" to off the functionality of categories tree (YTMA contribution) http://www.oscommerce.com/community/contri...all/search,YATM degrades as follows : 1. Counts in admin = TRUE When final subcategory is chosen the products page is displayed and the tree menu stays opened as choosen and selected subcategory highlighted ... Please see bellow demo : http://www.delko.si/adapta/sql/commerce/ca...php?language=en 2. Counts in admin = FALSE When final category is chosen the products are displayed but the tree colapses to "home" ... ?!??! Please check demo at : http://www.delko.si/sql/eshop/catalog/index.php?language=en Please note the demo sites are totaly seperated, just for you all to see how it works ... What should I do tp have counts disabled and maintain the full functionality of the tree ... The code from the cattegories.php is as bellow ... You can also check the YATM contrib for the files ! THANKS for any HELP ! Suhy
suhy Posted April 7, 2007 Author Posted April 7, 2007 At the 2nd explanation I was thinking final subcategory of course ... sorry ... whole day infront my PC, eyes dark red ... :blink: The code of categories.php <?php /* ------------------------------------------------ YATM - Yet Another Tree Menu Tigra Tree Menu for osCommerce ©2004 Medreces [email protected] ©2006 Andrew_Yer [email protected] Released under the GNU General Public License ------------------------------------------------ */ ?> <!-- tigra tree menu //--> <tr> <td align="left"><div id="treemenu"><noscript> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => '<font color="' . $font_color . '">' . BOX_HEADING_CATEGORIES . '</font>'); new infoBoxHeading($info_box_contents, true, true); $categories = array(); $expanded = array(); // This is the time to live of the tree_items.js file in seconds. $time_to_live = 300; $categories_string = ''; $tree_items_string = ''; $current_category_name = ''; if (tep_not_null($cPath)) { $expanded = explode("_", $cPath); } $expanded = array_reverse($expanded); $expanded[] = 0; $expanded = array_reverse($expanded); loadTree(); loadBranch(0, 0); cache_tree_items(); $info_box_contents = array(); $info_box_contents[] = array('text' => $categories_string); new infoBox($info_box_contents); function loadBranch($parent_id, $depth = 0, $draw_category = true) { global $categories, $categories_string, $expanded, $tree_items_string, $current_category_name; foreach ($categories[$parent_id]['child_list'] as $cat) { if ($draw_category) { $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $categories[$cat]['path']) . '">'; if ((count($expanded) > $depth + 1) && ($categories[$cat]['categories_id'] == $expanded[$depth + 1])){ $categories_string .= '<b>'; } $categories_string .= str_repeat(' ', $depth); $categories_string .= $categories[$cat]['categories_name']; if ($categories[$cat]['child_count'] > 0) { $categories_string .= '->'; } if ((count($expanded) > $depth + 1) && ($categories[$cat]['categories_id'] == $expanded[$depth + 1])) { $categories_string .= '</b>'; } $categories_string .= '</a>'; if (SHOW_COUNTS == 'true') { if ((CATEGORIES_COUNT_ZERO == '1' and $categories[$cat]['count_with_sub'] == 0) or $categories[$cat]['count_with_sub'] >= 1) { $categories_string .= ' (' . $categories[$cat]['count_with_sub'] . ')'; } } $categories_string .= '<br />'; } $tree_items_string .= ",\n" . str_repeat(" ", $depth + 2) . "['" . addslashes($categories[$cat]['categories_name']); if (SHOW_COUNTS == 'true') { if ((CATEGORIES_COUNT_ZERO == '1' and $categories[$cat]['count_with_sub'] == 0) or $categories[$cat]['count_with_sub'] >= 1) { $tree_items_string .= ' (' . $categories[$cat]['count_with_sub'] . ')'; } } $tree_items_string .= "', '" . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $categories[$cat]['path']) . "', " . 'false'; if ((count($expanded) > $depth + 1) && ($categories[$cat]['categories_id'] == $expanded[$depth + 1])) { $current_category_name = $categories[$cat]['categories_name']; if (SHOW_COUNTS == 'true') { if ((CATEGORIES_COUNT_ZERO == '1' and $categories[$cat]['count_with_sub'] == 0) or $categories[$cat]['count_with_sub'] >= 1) { $current_category_name .= ' (' . $categories[$cat]['count_with_sub'] . ')'; } } loadBranch($categories[$cat]['categories_id'], $depth + 1); } else { loadBranch($categories[$cat]['categories_id'], $depth + 1, false); } $tree_items_string .= "\n" . str_repeat(" ", $depth + 2) . ']'; } } function loadTree() { global $categories, $languages_id, $cPath, $expanded; // Get the categories data and put it into the tree $categories[0] = array('categories_id' => 0, 'parent_id' => -1, 'categories_name' => 'root', 'child_count' => 0, 'child_list' => array(), 'count' => 0, 'count_with_sub' => 0, 'path' => '0'); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); while ($groups_cat = tep_db_fetch_array($categories_query)) { $categories[$groups_cat['categories_id']] = array('categories_id' => $groups_cat['categories_id'], 'parent_id' => $groups_cat['parent_id'], 'categories_name' => $groups_cat['categories_name'], 'child_count' => 0, 'child_list' => array(), 'count' => 0, 'count_with_sub' => 0, 'path' => $groups_cat['categories_id']); } //Count child for each category foreach($categories as $cat) { if (array_key_exists($cat['parent_id'], $categories)) { $categories[$cat['parent_id']]['child_count']++; array_push($categories[$cat['parent_id']]['child_list'], $cat['categories_id']); } } if (SHOW_COUNTS == 'true') { // Populate the product counts array $products_query = tep_db_query("select count(p2c.products_id) as count, p2c.categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS . " p where p.products_id=p2c.products_id and p.products_status='1' group by categories_id"); while ($productsCount = tep_db_fetch_array($products_query)) { if (array_key_exists($productsCount['categories_id'], $categories)) { $categories[$productsCount['categories_id']]['count'] = $productsCount['count']; $categories[$productsCount['categories_id']]['count_with_sub'] = $productsCount['count']; } } foreach($categories as $cat) { $parentId = $cat['parent_id']; // walkup to root and update counters and cPath. don`t count for root while($parentId > 0 and array_key_exists($parentId, $categories)) { $categories[$parentId]['count_with_sub'] += $cat['count']; $categories[$cat['categories_id']]['path'] = $parentId . '_' . $categories[$cat['categories_id']]['path']; $parentId = $categories[$parentId]['parent_id']; } } } return; } function cache_tree_items() { global $tree_items_string, $language, $time_to_live; $filename = DIR_FS_CATALOG . 'temp/tree_items_' . $language . '.js'; $difference = 0; if (file_exists($filename)) { $now = time(); $filetime = filemtime($filename); $difference = $now - $filetime; } if (!file_exists($filename) || ($difference > $time_to_live)) { if ($fp = @fopen($filename, 'w')) { flock($fp, 2); fputs($fp, "var TREE_ITEMS = [\n" . " ['', 0, false" . $tree_items_string . "\n ]\n];"); flock($fp, 3); fclose($fp); } } } ?> </noscript></div></td> </tr> <script language="JavaScript"> load_tree_menu = 0; </script> <script language="JavaScript" src="includes/jscript_tree.js"></script> <script language="JavaScript"> var tree_icons_dir = "images/icons/treemenu"</script> <script language="JavaScript" src="includes/jscript_tree_tpl.js"></script> <script language="JavaScript" src="temp/tree_items_<?php echo $language ?>.js"></script> <script language="JavaScript"> function getElem (idName) { return document.all ? document.all[idName] : document.getElementById(idName);}; if (getElem('treemenu') && load_tree_menu) { getElem('treemenu').innerHTML = ''; document.write('<tr><td align="left">'); document.write('<table border="0" width="100%" cellspacing="0" cellpadding="0">'); document.write(' <tr>'); document.write(' <td height="14" class="infoBoxHeading"><img src="images/infobox/corner_left.gif" border="0" alt=""></td>'); document.write(' <td width="100%" height="14" class="infoBoxHeading"><?php echo BOX_HEADING_CATEGORIES ?></td>'); document.write(' <td height="14" class="infoBoxHeading" nowrap><img src="images/infobox/corner_right.gif" border="0" alt=""></td>'); document.write(' </tr>'); document.write('</table>'); document.write('<table style=" border:1px solid #A6B3BA; border-width:0px 1px 1px 1px;" width="100%" cellspacing="0" cellpadding="1" class="infoBox"><tr><td><table border="0" width="100%" cellspacing="0" cellpadding="3" class="infoBoxContents"><img style="padding-left:2px;" src="images/home.gif"><tr><td>'); new tree (TREE_ITEMS, TREE_TPL, '<?php echo $current_category_name ?>'); document.write('</td></tr></table><br></td></tr></table></td></tr>'); } </script> <!-- tigra tree menu eof //-->
Recommended Posts
Archived
This topic is now archived and is closed to further replies.