Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need Help with Categories


KoshaK

Recommended Posts

Hi Crowd,

 

Have been looking for the solution but can't find anything...

 

I would like to have All Products to be listed under the Category in the menu.

 

For example:

 

Category 1

-Product Name1

-Product Name2

-Product Name3

Category 2

Category 3

 

so when user click to Product NameX it's goes straight to the product page.

 

There is only workaround I was able to think about is to name SubCategories by Product Names, but unfortunately this is not suitable for my Store.

 

Any suggestions?

 

Regards

Kos.

Link to comment
Share on other sites

Here is a bit of code, that I belve responsible for Categories/subcategories listing:

<?   // ---- CATEGORIES

 function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

  if(!$tree[$counter]['level']){			   

$categories_string .= $categories_string ? '<tr><td bgcolor=#68A200 align=center><img src=images/m15.gif width=162 height=1></td></tr>' : '';			 

$categories_string .= '<tr><td bgcolor=#68A200 height=25 class=ch6><img src=images/m14.gif width=5 height=5 align=absmiddle>  <a class=ml3 href=';

if ($tree[$counter]['parent'] == 0) {
  $cPath_new = 'cPath=' . $counter;
} else {
  $cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link('index.php', $cPath_new) . '>';
// display categry name
$categories_string .= $tree[$counter]['name'];
$categories_string .= '</a></td></tr> ';

  }else{  // SUBCATEGORY

$categories_string .= '<tr><td bgcolor=#68A200 height=25 class=ch6><img src=images/m14.gif width=5 height=5 align=absmiddle>  ';

for($i=0;$i<$tree[$counter]['le vel'];$i++)
 $categories_string .= '     ';

$categories_string .= '     <a class=ml3 style="font-weight:normal;" href=';   
if ($tree[$counter]['parent'] == 0) {
  $cPath_new = 'cPath=' . $counter;
} else {
  $cPath_new = 'cPath=' . $tree[$counter]['path'];
}
$categories_string .= tep_href_link('index.php', $cPath_new) . '>-';
// display category name
$categories_string .= $tree[$counter]['name'];
$categories_string .= '</a></td></tr>';
  }  

if ($tree[$counter]['next_id'] != false) {
  tep_show_category($tree[$counter]['next_id']);
}  
 }



 define(TABLE_CATEGORIES, "categories");
 define(TABLE_CATEGORIES_DESCRIPTION, "categories_description");
 $categories_string = '';
 $tree = array();

 $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='" . (int)$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) {
$new_path = '';
reset($cPath_array);
while (list($key, $value) = each($cPath_array)) {
  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 = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  if (tep_db_num_rows($categories_query)) {
	$new_path .= $value;
	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'];
	}
	$tree[$last_id]['next_id'] = $tree[$value]['next_id'];
	$tree[$value]['next_id'] = $first_id;
	$new_path .= '_';
  } else {
	break;
  }
}
 }
 $categories_string .=  '';
 tep_show_category($first_element); 
 $categories_string .=  '';

 echo $categories_string;
?>

Link to comment
Share on other sites

I saved a file back in March while I was working on a menu package .. I wish to emphasize though that this was never an intended mod or contribution. It was just a byproduct of some work I was doing.

 

What I mean by this is .. no warranty whatsoever as to whether this will work or in fact function at all.

 

I think it was based on RC2 though.

 

The file replaces (after you have backed up the existing file) catalog/includes/boxes/categories.php

 

Give it a go see what happens.

 

 

<?php
/*
 $Id: categories.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/
#### SUB CATS EXPANDED BY DEFAULT                 ####
#### Version 1.0 - 28th March 2008                ####
#### FWR Media                                    ####
#### www.fwrmedia.co.uk                           ####
#### Robert Fisher                                ####
 function tep_show_category($counter) {
   global $tree, $categories_string, $cPath_array;

   for ($i=0; $i<$tree[$counter]['level']; $i++) {
     $categories_string .= "  ";
   }

   $categories_string .= '<a href="';

   if ($tree[$counter]['parent'] == 0) {
     $cPath_new = 'cPath=' . $counter;
   } else {
     $cPath_new = 'cPath=' . $tree[$counter]['path'];
   }

   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '<b>';
   }

// display category name
   $categories_string .= $tree[$counter]['name'];

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '</b>';
   }

   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 />';

   if (isset($tree[$counter]['next_id']) && $tree[$counter]['next_id'] != false) {
     tep_show_category($tree[$counter]['next_id']);
   }
 }
?>
<!-- categories //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $categories_string = '';
 $tree = array();

 $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 c.parent_id, sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
   if ( $categories['parent_id'] == 0 ) {
   $parents[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 0,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);
   } elseif( isset($parents[$categories['parent_id']]) ) {
   $level1[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 1,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);
   } else {
   $level2[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 2,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);
   }
 }
tep_db_free_result($categories_query);
 foreach( $parents as $cat => $array ) {
   if( isset($lastcat) ) $tree[$lastcat]['next_id'] = $cat;
   ( isset($first_element) ? NULL : $first_element = $array['path'] );
   unset($l1_first_pass, $l2_first_pass, $lastcat, $l1_previous_id, $l2_previous_id);
   $tree[$cat] = array('name' => $array['name'],
                       'parent' => $array['parent'],
                       'level' => $array['level'],
                       'path' => $array['path']);
   foreach( $level1 as $l1_cat => $l1_array ) {
     ( isset($l1_first_pass) ? NULL : $l1_first_pass = true );
     if ($cat == $l1_array['parent']) {
     $tree[$l1_array['path']] = array('name' => $l1_array['name'],
                                    'parent' => $l1_array['parent'],
                                    'level' => $l1_array['level'],
                                    'path' => $cat . '_' . $l1_array['path']);
     if($l1_first_pass) {
     $tree[$l1_array['parent']]['next_id'] = $l1_array['path']; // Set the parent next id
     }
     $l1_first_pass = false;
     if (isset($l1_previous_id)) {
     $tree[$l1_previous_id]['next_id'] = $l1_array['path'];
     }
     $l1_previous_id = $l1_array['path'];
     $lastcat = $l1_cat;
     }
     if (isset($level2))
     foreach( $level2 as $l2_cat => $l2_array ) {
       ( isset($l2_first_pass) ? NULL : $l2_first_pass = true );
       if ($l1_cat == $l2_array['parent'] && $cat == $l1_array['parent']) {
       $tree[$l2_array['path']] = array('name' => $l2_array['name'],
                                      'parent' => $l2_array['parent'],
                                      'level' => $l2_array['level'],
                                      'path' => $cat . '_' . $l1_cat . '_' . $l2_cat);
       if($l2_first_pass) {
       $tree[$l2_array['parent']]['next_id'] = $l2_array['path'];
       } else $tree[$l2_array['path']]['level'] = 3;
       $l2_first_pass = false;
       if (isset($l2_previous_id)) {
       $tree[$l2_previous_id]['next_id'] = $l2_array['path'];
       }
       $l2_previous_id = $l2_array['path'];
       $lastcat = $l2_cat;
       }
     }
     }
   }
   unset( $parents, $level1, $level2, $l1_first_pass, $l2_first_pass, $lastcat, $l1_previous_id, $l2_previous_id );
 ############################################
 tep_show_category($first_element);

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);

 new infoBox($info_box_contents);
?>
           </td>
         </tr>
<!-- categories_eof //-->

Link to comment
Share on other sites

there are many menu that can show product

 

like:

 

css menu http://addons.oscommerce.com/info/4589

I used 0.4.1, to install rename the categories_css.php to categories.php and put in boxes. Alter the css in file to match your site

 

or

 

DropDownMenu v2.0 (Advanced Search infobox) http://addons.oscommerce.com/info/2306

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Replacing the code does not gave any result :huh:

 

going to try addons suggested by Spooks.

 

Thanks for your quick reply and sugestions!!!!!

 

If you are talking about my code .. you save it as a file catalog/includes/boxes/categories.php (replacing the existing one)

 

If you have your cache on, then reset the categories cache.

 

It is impossible that it does nothing .. it may do nasty things or it may just work .. nothing is what it most certainly won't do.

Link to comment
Share on other sites

If you are talking about my code .. you save it as a file catalog/includes/boxes/categories.php (replacing the existing one)

 

If you have your cache on, then reset the categories cache.

 

It is impossible that it does nothing .. it may do nasty things or it may just work .. nothing is what it most certainly won't do.

 

well, you see, the categories code is included in header.php file, any way I have tried both ways and it's the same: the error I receive is:

Warning: Invalid argument supplied for foreach() in /home/users/cellnetto/public_html/shop/includes/header.php on line 358

which is:

$tree[$cat] = array('name' => $array['name'],
'parent' => $array['parent'],
'level' => $array['level'],
'path' => $array['path']);
***LINE 358****  foreach( $level1 as $l1_cat => $l1_array ) {
( isset($l1_first_pass) ? NULL : $l1_first_pass = true );
if ($cat == $l1_array['parent']) {
$tree[$l1_array['path']] = array('name' => $l1_array['name'],
'parent' => $l1_array['parent'],
'level' => $l1_array['level'],

 

The Menu suggested by SAM is works fine, but it does not displayed the way I need.

 

 

At the moment it's displayed all product on right side of the menu

Category1->Product1.1

Category2-> Product1.2

Category3-> Product1.3

 

Due to I have about 50+ products in the category the method above does not fit to the screen, of cause I can scroll down with mouse wheel, but if sudenly I remove the mouse pointer from menu, will have to go back to top again.

 

I need the product to be displayed this way:

Category1->

Product1.1

Product1.2

Product1.3

Category2->

Category3->

 

Category1->

Category2->

Product2.1

Product2.2

Product2.3

Category3->

 

 

Any help? please? :blush:

 

this is the only part that holds me back from put the shop on-line...

 

regards,

Kos

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...