Show categories and subcategories
#1
Posted 11 May 2003 - 09:44 PM
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
Posted 13 May 2003 - 03:17 PM
#3
Posted 13 May 2003 - 11:11 PM
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
Posted 25 May 2003 - 03:57 AM
I'm wondering about the same thing!
Your thoughts are much appreciated!
Thanks much!
#5
Posted 31 May 2003 - 01:29 AM
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
Posted 01 June 2003 - 06:06 PM
Thanks a million for posting this!
This is going to be so helpful
You are the best!
Cheers,
Dan
#7
Posted 01 June 2003 - 08:52 PM
Regards and also thanks,
Matt
#8
Posted 08 September 2003 - 10:04 PM
Thanks.
#9
Posted 07 October 2003 - 12:16 PM
Kim
#10
Posted 19 February 2005 - 03:48 AM
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
Posted 01 March 2005 - 04:58 AM
athyholdt, on Feb 18 2005, 08:48 PM, said:
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.
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
Posted 01 March 2005 - 08:20 AM
theman, on Mar 1 2005, 05:58 AM, said:
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
That would probably be useful for me too, I will have to think about it a bit.
#13
Posted 01 March 2005 - 12:30 PM
http://www.oscommerce.com/community/contri...ns,1014/page,18
Cheers.
#14
Posted 02 March 2005 - 08:18 AM
athyholdt, on Mar 1 2005, 05:30 AM, said:
http://www.oscommerce.com/community/contri...ns,1014/page,18
Cheers.
thanks
#15
Posted 02 March 2005 - 11:44 AM
theman, on Mar 2 2005, 09:18 AM, said:
thanks
Here is a screenshot.
http://homepage.mac.com/andreast/.Public/screen.jpg
#16
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
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
Posted 01 April 2005 - 04:23 PM
rebelina, on Apr 1 2005, 04:52 PM, said:
"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
Posted 26 July 2006 - 04:32 AM
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
Posted 27 July 2006 - 01:46 AM
#20
Posted 22 January 2007 - 05:58 PM









