Guest Posted October 3, 2005 Posted October 3, 2005 I'm new to the OSCommerce world and am working on a site where I'd like to retain the look of their menu system, but when you click on a top level category, instead of opening a page for it, I'd like it to highlight the first subcategory and open that page instead. I have no need for a top level category page since it will contain no product, but I don't want to lose the ability to expand/collapse either. Ex: Video Games -- Playstation -- Gamecube -- Xbox When someone clicks on the Video Games category, I would like it to expand to show Playstation/Gamecube/Xbox, but highlight and open up the Playstation subcategory. Thanks! Ian
Guest Posted October 3, 2005 Posted October 3, 2005 There are several contributions for this type of thing like this one: (jscript based) http://www.oscommerce.com/community/contributions,3069 There are others that are css based, search the contributions for categories tree.
Guest Posted October 5, 2005 Posted October 5, 2005 I tried a few out... but they aren't really providing the solution I need. Basically, the very top most category needs to link by default to the first subcategory, I would think this is a change that could possibly be made in either index.php or application_top.php. I've searched google/forums/and the contribs for hours with no luck. Ex: User clicks on Hardware (Cpath=1) Instead of the page pulling up as Cpath=1, it should pull up as Cpath=1_15 (or whatever the first subcategory should be). Does that make sense? Any help is greatly appreciated.
Guest Posted October 5, 2005 Posted October 5, 2005 What's the category box you're using? Perhaps if you post the code I may able to help a bit. Basically it needs a link override on the parent category from the child.
Guest Posted October 5, 2005 Posted October 5, 2005 I was playing around with the Great Catagories contrib: http://www.oscommerce.com/community/contri...search,category <?php /* $id: Great Categories v2.1 2005/07/09 14:00:00 willross Exp $ http://www.palaia.com/ujp/ - [email protected] *** For use with standard install of osCommerce 2.2MS2+ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2005 osCommerce Released under the GNU General Public License */ function tep_show_category($counter) { global $tree, $categories_string, $cPath_array, $aa; for ($a=0; $a<$tree[$counter]['level']; $a++) { // $categories_string .= "??"; } //category start if ($tree[$counter]['level'] == 0) { if ($aa == 1) { $categories_string .= '<img src="images/pixel_trans.gif" border="0" alt="" width="100%" height="2"><br><img src="images/pixel_ltgray.gif" border="0" alt="" width="100%" height="1"><br><img src="images/pixel_trans.gif" border="0" alt="" width="100%" height="2">'; } else {$aa=1;} } if ($tree[$counter]['level'] == 0) {$categories_string .= '<div id="topcat">';} if ($tree[$counter]['level'] == 1) {$categories_string .= '<div id="secondcat">';} if ($tree[$counter]['level'] == 2) {$categories_string .= '<div id="thirdcat">';} if ($tree[$counter]['level'] == 3) {$categories_string .= '<div id="fourthcat">';} if ($tree[$counter]['level'] == 4) {$categories_string .= '<div id="fifthcat">';} $categories_string .= '<a'; if ( ($cPath_array) && (@in_array($counter, $cPath_array)) ) { $categories_string .= ' class="activelink"'; } if ($tree[$counter]['parent'] == 0) { $cPath_new = 'cPath=' . $counter; } else { $cPath_new = 'cPath=' . $tree[$counter]['path']; } $categories_string .= ' href="'.tep_href_link(FILENAME_DEFAULT, $cPath_new); $categories_string .= '">'; // display category name if (tep_has_category_subcategories($counter) || $tree[$counter]['level'] == 0) { if ( ($cPath_array) && (@in_array($counter, $cPath_array)) ) { $categories_string .= '<span class="catwithsubs">'.tep_image(DIR_WS_IMAGES . 'categories/arrow_down.gif', '', '9', '9') . "</span>"; } else { $categories_string .= '<span class="catwithsubs">'.tep_image(DIR_WS_IMAGES . 'categories/arrow_right.gif', '', '9', '9') . "</span>"; } } else { $categories_string .= '<span class="catwithnosubs">' .tep_image(DIR_WS_IMAGES . 'categories/arrow_bullet.gif', 'nokta', '9', '9') . "</span>"; } //category name $categories_string .= $tree[$counter]['name']; if ( ($cPath_array) && (@in_array($counter, $cPath_array)) ) { //end of active link $categories_string .= ''; } if (tep_has_category_subcategories($counter)) { $categories_string .= ''; } $categories_string .= '</a>'; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) { $categories_string .= '(' . $products_in_category . ')'; } } // $categories_string .= '<br>'; $categories_string .= '</div>'; if ($tree[$counter]['next_id']) { tep_show_category($tree[$counter]['next_id']); } } ?> <!-- categories //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => BOX_HEADING_CATEGORIES); new infoBoxHeading($info_box_contents, true, false); $categories_string = '<div id="thecategories">'; $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.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name"); while ($categories = tep_db_fetch_array($categories_query)) { $tree[$categories['categories_id']] = array( 'name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false); if (isset($parent_id)) { $tree[$parent_id]['next_id'] = $categories['categories_id']; } $parent_id = $categories['categories_id']; if (!isset($first_element)) { $first_element = $categories['categories_id']; } } //------------------------ if ($cPath) { $cPath_array = split('_', $cPath); reset($cPath_array); while (list($key, $value) = each($cPath_array)) { $new_path .= $value; unset($parent_id); unset($first_id); $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.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name"); $category_check = tep_db_num_rows($categories_query); while ($row = tep_db_fetch_array($categories_query)) { $tree[$row['categories_id']] = array( 'name' => $row['categories_name'], 'parent' => $row['parent_id'], 'level' => $key+1, 'path' => $new_path . '_' . $row['categories_id'], 'next_id' => false ); if (isset($parent_id)) { $tree[$parent_id]['next_id'] = $row['categories_id']; } $parent_id = $row['categories_id']; if (!isset($first_id)) { $first_id = $row['categories_id']; } $last_id = $row['categories_id']; } if ($category_check != 0) { $tree[$last_id]['next_id'] = $tree[$value]['next_id']; $tree[$value]['next_id'] = $first_id; } $new_path .= '_'; } } tep_show_category($first_element); $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => $categories_string.'</div>'); new infoBox($info_box_contents); ?> </td> </tr> <!-- categories_eof //-->
Guest Posted October 5, 2005 Posted October 5, 2005 ok there are 2 functions I could think of that could help. All are in general.php 1. function tep_count_products_in_category - To check if there are products in a category 2. function tep_get_subcategories - To get a list of subs from the current category The code in this file that sets the path is this: if ($tree[$counter]['parent'] == 0) { $cPath_new = 'cPath=' . $counter; } else { $cPath_new = 'cPath=' . $tree[$counter]['path']; } you add the code right below it to modify it. Now the cPath_new is the category parameter link. The last element of the cPath_new indicates the category the code is about to set. So you retrieve that, you call the tep_count_products_in_category (if there are products you do nothing) otherwise you call tep_get_subcategories to retrieve the list of sub-categories. For each of them you check for products. The first one you find that has products, is the id to create the new link.
Guest Posted October 5, 2005 Posted October 5, 2005 Thanks for the help, those clues and some more code did the trick!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.