Jump to content



Latest News: (loading..)

- - - - -

Show categories and subcategories


  • Please log in to reply
29 replies to this topic

#1   mattkhan

mattkhan
  • Members
  • 63 posts
  • Real Name:Matthias Khan

Posted 11 May 2003 - 09:44 PM

Hi there,

I did some modification to the way the "new" products are shown.  Now I would like to use the same style for my categories and sub categories.

To clearify...  When I click on a main category I get a page with a list of sub categories and the new products underneith.  I want to get rid of that and display all products of this main categorie in the same style as the new products.

This way the only way to get to a sub category would be the menu on the left, but that's OK.  When I now click on a sub category the products shown a limited to that sub category and so on.

One way would be to change the file <b>product_listing.php</b> somehow similar to <b>new_products.php</b> and use the appropriate SQL statement (whatever that would be).

I am somehow a little scared since there are so many "functions"  within the default.php that effect what will be shown on the <b>product_listing.php</b>, that I will detsroy needed functionality without knowing.

Please help   :idea:

Regards Matt

#2   Collect

Collect
  • Members
  • 10 posts
  • Real Name:Roberto Reis

Posted 13 May 2003 - 03:17 PM

I think there is a contribution for this called something top categories.

#3   mattkhan

mattkhan
  • Members
  • 63 posts
  • Real Name:Matthias Khan

Posted 13 May 2003 - 11:11 PM

I believe you ment this contribution http://www.oscommerce.com/community/contributions,1145?

But that's not what I am looking for.  Remeber the way the new products are displayed?  I would like to have all products displayed that way directly when you click the category in the left menu.

e.g.  When you click on a top category that contains, let's say 50 products, and you click on this catgeory you'll see all 50 products out of that category (of course being split into x pages).  When you now click on a subcategory that contains 20 prodcuts you would see the same style page, but the output now is limted to the products within this subcategory.

Clear?

Thanks Matt

#4   CodeConfused

CodeConfused
  • Members
  • 44 posts
  • Real Name:Call me Dan!
  • Location:Boston, MA

Posted 25 May 2003 - 03:57 AM

Did you ever figure out how to do this?
I'm wondering about the same thing!

Your thoughts are much appreciated!
Thanks much!

#5   mattkhan

mattkhan
  • Members
  • 63 posts
  • Real Name:Matthias Khan

Posted 31 May 2003 - 01:29 AM

Hi CodeConfused,

yes I solved it.  I will post some code underneith hoping that this helps.

  $cPathA = explode("_", $cPath);
      $size = sizeof($cPathA)-1;
      $subcategories_array = array();
      tep_get_subcategories($subcategories_array, $cPathA[$size]);
      $size_sc = sizeof($subcategories_array);
      for($i = 0; $i < $size_sc; $i++){
        $cat_Search .= "p2c.categories_id = '" . $subcategories_array[$i] . "' or ";
      }
      $cat_Search .= "p2c.categories_id = '" . $cPathA[$size] . "'";
  
  $result = tep_db_query("select p.products_id, p.products_image, p.products_price from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS . " p where p2c.products_id = p.products_id and p.products_status = '1' and (" . $cat_Search . ")");

Drop me a note, if that works for you.  This subject is already far away to me and I am not sure, if the function "tep_get_subcategories" is a standard one or written/modified by me.  We've put more than 400 hours into our osCommerce project by now, so it gets hard to remember everything we did ;-)

Best regards Matt

#6   CodeConfused

CodeConfused
  • Members
  • 44 posts
  • Real Name:Call me Dan!
  • Location:Boston, MA

Posted 01 June 2003 - 06:06 PM

Hi Matt,

Thanks a million for posting this!
This is going to be so helpful  :D
You are the best!

Cheers,
Dan

#7   mattkhan

mattkhan
  • Members
  • 63 posts
  • Real Name:Matthias Khan

Posted 01 June 2003 - 08:52 PM

It was a pleasure, especially that I might have been able to give something back, after so much help from so many people in this forum.

Regards and also thanks,

Matt   :D

#8   only2empires

only2empires
  • Validating
  • 170 posts
  • Real Name:Cathy

Posted 08 September 2003 - 10:04 PM

I hope you can still remember this, but where does this code go? Nothing on the thread gives a catalog/???

Thanks.

#9   kborup

kborup
  • Members
  • 53 posts
  • Real Name:Kim Borup

Posted 07 October 2003 - 12:16 PM

Where did you use this code... I am trying to find out how to implement it.

Kim

#10   athyholdt

athyholdt
  • Members
  • 35 posts
  • Real Name:Andreas

Posted 19 February 2005 - 03:48 AM

I see around the forum that quite a few people wanted this functionality, including myself, but no clear solution was presented as I could locate.

I borrowed some of the code from a previous post that does most of the hard work.
As I am a PHP newbie, I apologise for the somewhat crude approach, but I got it working and that's the main thing for me. Feel free to polish it up. ;)

The file to be edited is catalog/index.php

First, since I never want categories or subcategories headings in the main panel, I makes sure that if there are any products in the current category or in a subcategory a product listing will appear, like this:

At around line 20 find

    if ($cateqories_products['total'] > 0) {
      $category_depth = 'products'; // display products
    } else {


replace with

// Begin show all subcategories mod.
    if (tep_count_products_in_category($cPath) > 0) {
// End show all subcategories mod.
      $category_depth = 'products'; // display products
    } else {



Then the actual search in the database has to be modified to include all subcategories, like this:


At around line 186 find

// We show them all
        $listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
      }
    }


Replace with



// We show them all

// Begin show all subcategories mod.

$cPathA = explode("_", $cPath);
$size = sizeof($cPathA)-1;
$subcategories_array = array();
tep_get_subcategories($subcategories_array, $cPathA[$size]);
$size_sc = sizeof($subcategories_array); //Subcat count
$cat_Search = "(";
for($i = 0; $i < $size_sc; $i++){
$cat_Search .= "p2c.categories_id = '" . $subcategories_array[$i] . "' or ";
}
$cat_Search .= "p2c.categories_id = '" . $cPathA[$size] . "'" . ")";  

$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and ". $cat_Search . "";

      }
    }

// End show all subcategories mod.


That's about it as far as I recall, it's been about a week since I did this and these things fade fast.
If it works for you, great. If not, post a message here and I will see what I may have overlooked.

cheers.

#11   theman

theman
  • Members
  • 163 posts
  • Real Name:AL S

Posted 01 March 2005 - 04:58 AM

athyholdt, on Feb 18 2005, 08:48 PM, said:

// End show all subcategories mod.
That's about it as far as I recall, it's been about a week since I did this and these things fade fast.
If it works for you, great. If not, post a message here and I will see what I may have overlooked.

cheers.

<{POST_SNAPBACK}>


works good thanks


i was wonderin maybe if anyone knows how to mod this a bit and have it list by sub category...ie
if i click hardware it would list all products but list

like
  CDROM Drives
LIST ALL PRODUCTS FROM CDROM DRIVES
  Graphics Cards (2)
LIST ALL PRODUCTS FROM GRAPHICS CARDS
  Keyboards (1)
etc
etc

Edited by theman, 01 March 2005 - 05:03 AM.


#12   athyholdt

athyholdt
  • Members
  • 35 posts
  • Real Name:Andreas

Posted 01 March 2005 - 08:20 AM

theman, on Mar 1 2005, 05:58 AM, said:

works good thanks
i was wonderin maybe if anyone knows how to mod this a bit and have it list by sub category...ie
if i click hardware it would list all products but list

like
  CDROM Drives
LIST ALL PRODUCTS FROM CDROM DRIVES
  Graphics Cards (2)
LIST ALL PRODUCTS FROM GRAPHICS CARDS
  Keyboards (1)
etc
etc

<{POST_SNAPBACK}>



That would probably be useful for me too, I will have to think about it a bit.

#13   athyholdt

athyholdt
  • Members
  • 35 posts
  • Real Name:Andreas

Posted 01 March 2005 - 12:30 PM

I found that the following contribution worked quite well, the subcategories are listed at the top, though, maybe not exactly what your were looking for. It works fine with my mod too so all products within the current category/subcategories are displayed as well.

http://www.oscommerce.com/community/contri...ns,1014/page,18


Cheers.

#14   theman

theman
  • Members
  • 163 posts
  • Real Name:AL S

Posted 02 March 2005 - 08:18 AM

athyholdt, on Mar 1 2005, 05:30 AM, said:

I found that the following contribution worked quite well, the subcategories are listed at the top, though, maybe not exactly what your were looking for. It works fine with my mod too so all products within the current category/subcategories are displayed as well.

http://www.oscommerce.com/community/contri...ns,1014/page,18
Cheers.

<{POST_SNAPBACK}>

mm i dont see it changing anything? do you mind posting a page where i can see it live in action..maybe im doin something wrong

thanks

#15   athyholdt

athyholdt
  • Members
  • 35 posts
  • Real Name:Andreas

Posted 02 March 2005 - 11:44 AM

theman, on Mar 2 2005, 09:18 AM, said:

mm i dont see it changing anything? do you mind posting a page where i can see it live in action..maybe im doin something wrong

thanks

<{POST_SNAPBACK}>



Here is a screenshot.

http://homepage.mac.com/andreast/.Public/screen.jpg

#16   rebelina

rebelina
  • Members
  • 22 posts
  • Real Name:Rebecca

Posted 01 April 2005 - 03:52 PM

athyholdt, on Mar 2 2005, 11:44 AM, said:


Using the mod published on this board by Athyholdt (19/02/05) I managed to get all products (including those in sub categories) showing, which is just what I wanted (thanks  :D ).  

But I've lost the list of sub-categories at the top so that the user can "drill down".  The sub cats are available via the left hand nav, but I still wanted them displayed at the top.  Anyone else had this problem and found a fix?

#######

For info, I looked at http://www.oscommerce.com/community/contri...ns,1014/page,18 as suggested on this board, but wasn't sure what it was providing.  It seems to suggest the default behavious of osCommerce is to display all products (including those in sub cats).  But I am fairly sure that the default is to display the categories only.  I installed it anyway, but it had no effect on my site.

- Rebecca

#17   athyholdt

athyholdt
  • Members
  • 35 posts
  • Real Name:Andreas

Posted 01 April 2005 - 04:23 PM

rebelina, on Apr 1 2005, 04:52 PM, said:

For info, I looked at http://www.oscommerce.com/community/contri...ns,1014/page,18 as suggested on this board, but wasn't sure what it was providing.

"If you have product categories that have both products and subcategories, by default, OSC only displays the product listing in the main panel."
(quote from contribution)

This means that sub-categories does not display by default when the selected category has products.

This contribution fixes it so that sub-categories are listed on top when the selected category has products, as may be the case for some categories after my mod. Personally I thought I didn't need it, but when the suggestion came up earlier I found that I liked it and kept it, ref. my screenshot earlier.

I have to say that I don't remember if I had to tweak it to make it work, but if you still can not make it work for you I will have a go at it again.


Cheers.

#18   itsover

itsover
  • Members
  • 2 posts
  • Real Name:itsover

Posted 26 July 2006 - 04:32 AM

Hi,

As of osCommerce 2.2 Milestone 2 Update 051113, to do this modification, open catalog/index.php

1) Around line 20, replace

 	
   if ($cateqories_products['total'] > 0) {
	  $category_depth = 'products'; // display products
   } else {

with

 	
   if (tep_count_products_in_category($cPath) > 0) {
	  $category_depth = 'products'; // display products
   } else {

Same as previously.

2) Around line 195, replace

// We show them all
   $listing_sql = "select " . $_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";

with

// We show them all
   $cPathA = explode("_", $cPath);
   $size = sizeof($cPathA)-1;
   $subcategories_array = array();
   tep_get_subcategories($subcategories_array, $cPathA[$size]);
   $size_sc = sizeof($subcategories_array); //Subcat count
   $cat_Search = "(";
   for($i = 0; $i < $size_sc; $i++){
	  $cat_Search .= "p2c.categories_id = '" . $subcategories_array[$i] . "' or ";
   }
   $cat_Search .= "p2c.categories_id = '" . $cPathA[$size] . "'" . ")";
		
   $listing_sql = "select " . $_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and " . $cat_Search . "";

Hope this helps.

#19   jimmshepard

jimmshepard
  • Members
  • 7 posts
  • Real Name:Jimm Shepard

Posted 27 July 2006 - 01:46 AM

Somebody should make this a contribution!  This is a very simple yet amazing modification to the way that osCommerce works.  I've been searching the contrib section for this exact modification and I think it could help a lot of people.  I've never submitted a contribution but I think this one is worthy...

#20   shortd81

shortd81
  • Members
  • 270 posts
  • Real Name:Donald Woulard III
  • Gender:Male
  • Location:Deland, Florida

Posted 22 January 2007 - 05:58 PM

Now say if you have a sub sub categories can you get it to show in the main category instead of just in the sub category?