Forums / Setting Up Categories, Products, Attributes / How do I list products in sub category with in the parent category?

How do I list products in sub category with in the parent category?

Views: 15,219

Results 21 to 39 of 39
19 May 2016, 6:20 PM
#21
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

How do I list products in sub category with in the parent category?

No, it hasn't. I've asked for some help and testing it, several people contacted me and got the plugin to test it, but I've never gotten any feedback from anyone... I'm simply not sure if it's all good or it's no good... And I don't want to officially release it before getting confirmation it's all good because I don't really wanna spend hours and hours providing support for it and debugging it on the go...

My site - Pro ZC Help
My portfolio | My plugins

19 May 2016, 6:34 PM
#22
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How do I list products in sub category with in the parent category?

balihr:

So, imagine a store selling dresses. If we want to allow narrowing down with multiple factors, we are stuck with a category structure like:
From what you listed - this is what attributes are for and also linking can be used to your advantage

Zen-Venom Get Bitten

19 May 2016, 7:48 PM
#23
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

No, Kobra, the formatting on my previous post was totally messed up... Let me try again:

Dresses

  • long (sublevel 1)
    -- small (sublevel 2)
    -- medium (sublevel 2)
    -- large (sublevel 2)
    -- extra large (sublevel 2)
  • knee-length (sublevel 1)
    -- small (sublevel 2)
    -- medium (sublevel 2)
    -- large (sublevel 2)
    -- extra large (sublevel 2)
  • short
    -- small
    -- medium
    -- large
    -- extra large

No imagine a sub-sub-level on each tier:

  • long
    -- small
    --- red (sublevel 3)
    --- blue (sublevel 3)
    --- green
    --medium
    --- red
    --- green

etc etc. Hopefully, this makes more sense. Look at it like this: when you go to ebay and go to dresses, do you only see subcategories or do you see ALL dresses and have the (added) ability to narrow down using subcategories?

My site - Pro ZC Help
My portfolio | My plugins

19 May 2016, 10:10 PM
#24
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How do I list products in sub category with in the parent category?

Dresses
- long (sublevel 1)
-- small (sublevel 2)
-- medium (sublevel 2)
-- large (sublevel 2)
-- extra large (sublevel 2)
- knee-length (sublevel 1)
-- small (sublevel 2)
-- medium (sublevel 2)
-- large (sublevel 2)
-- extra large (sublevel 2)
- short
-- small
-- medium
-- large
-- extra large

The sizes should be attributes as should the colors - they should not be additional cats/sub-cats

Zen-Venom Get Bitten

19 May 2016, 10:34 PM
#25
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

kobra:

The sizes should be attributes as should the colors - they should not be additional cats/sub-cats

Wrong way of thinking, if you ask me. Why think of such exact scenarios only? Think wider. Actual example from a site that's using it:
adult toys

  • bondage
    -- cuffs
    --- ankle cuffs
    --- handcuffs
    --- thigh cuffs

Or, let's say lighting - see an example here: LIB.
EDIT: that's "light in the box DOT com", not sure why it's obfuscated... Link here
How would you do THAT with attributes? Notice how you have subcategories, and then ALL lighting products listed below. Then you choose "LED Lights" and you narrow it down to show all LED Lights subcategories, but at the same time you're seeing all LED lights below.

Besides, it's a matter of allowing choice, it's an added feature. I'm not saying it's a must-have because some sites really wouldn't benefit from it, that's why this is a plugin. Just like Canada Post plugin, for example - almost none of the US stores will ever need it, but for Canadians it's a very welcomed plugin... Same goes for this - SOME people might like it a lot...

My site - Pro ZC Help
My portfolio | My plugins

20 May 2016, 3:45 AM
#26
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How do I list products in sub category with in the parent category?

From your light example in the lighting cat there are

Ceiling Lights
Chandeliers
Island lights

click Ceiling Lights and you also have from the lighting cat

Chandeliers
Island lights
``` This is linking

From your first example they are distinct cats under "cuffs"

ankle cuffs
handcuffs
thigh cuffs

I see this as different than a dress in small, med, lrg and also in red, blue, and??

Zen-Venom Get Bitten

20 May 2016, 10:35 AM
#27
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I list products in sub category with in the parent category?

To throw something else into the mix about this. I tried the "linking" approach with a product on a default ZC 1.5.5.a store having the demo products. (Haven't gone back to try on older versions). I took both products from the Hardware->Graphic Cards category and linked them to the Hardware category. So the master_categories_id for the two products remained at the Graphic Cards category but now the product also exists in the Hardware category. When I navigated the front end using the categories dropdown I could see all the way to the Graphic Cards category, but if I were to click on the Hardware category, the only thing presented to me was the products.... I couldn't navigate to any of the sub-categories from the center of the screen. (Sure could still navigate using in this case the responsive dropdown menu).

I haven't tried balihr's plugin, but if it does entertain a center area "navigation" while a "product" (linked or not) is active in a category that also contains sub-categories, then that bridges the two issues.

Even if the colors as attributes were the items of categories, there have been plenty that would like to "search" by specific attribute and while database maintenance of such attribute to category relationship could become tedious, if that's how a store owner wishes to operate, then yes having the software that can accommodate is all the more beneficial. Further, if the software allows such "multiplacement" of product to include within a category and the other items of concern (sales discounts, specials, etc...) can still be applied as expected/desired/needed, then it truly does amplify the functionality at little to no cost for those that need or want that option.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

20 May 2016, 11:25 AM
#28
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

kobra:

From your light example in the lighting cat there are

Ceiling Lights
Chandeliers
Island lights

> click Ceiling Lights and you also have from the lighting cat
> ```
Chandeliers
Island lights
``` This is linking

No. Although very close, but it's not. I'm not sure what I'm doing wrong and why you can't understand what I'm try to explain... If you look at the parent category (Ceiling Lights), you see there are BOTH subcategories and products listed on that page and you will see all products from all subcategories, including ceiling lights, chandeliers, island lights, LAMPS etc. If you click on Ceiling Lights (subcategory), you will now see only the products that are listed in that category and you will no longer see any lamp items listed on that page because no lamp is in that subcategory.
Think of this is an option to FILTER using subcategories.

> **kobra:**
>
> From your first example they are distinct cats under "cuffs"
> ```
ankle cuffs
handcuffs
thigh cuffs

I see this as different than a dress in small, med, lrg and also in red, blue, and??

Yes, distinct cats. BUT, if you click on Cuffs, you would first see the three subcategories (so you can narrow down your search) and then followed by absolutely all cuffs listed, including ankle cuffs, handcuffs and thigh cuffs. How would you do that with attributes? Or linked products? Or whatever?

mc12345678:

but if it does entertain a center area "navigation" while a "product" (linked or not) is active in a category that also contains sub-categories, then that bridges the two issues.
That's EXACTLY what it does. Thank you!
See the screenshot I included in the previous post - it's from a vanilla install... The "New 1.2" category does NOT have any products, it only contains the 6 subcategories. However, if you navigate to the "New 1.2" category, you get to see the list of subcategories, then followed by all items from those subcategories. The first item you see there (the red 0) is actually an item posted in "Discount Qty" subcategory...

My site - Pro ZC Help
My portfolio | My plugins

20 May 2016, 2:14 PM
#29
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How do I list products in sub category with in the parent category?

I very much like the idea of this mod for the reasons others want it... but also because I think it may help with another problem I desperately want to solve.

Before I volunteer to test, let me see if I understand correctly. Your mod allows the display of all products existing in the subs below. The subs then act as filters, further narrowing product display each time a visitor clicks. If that is correct... AWESOME! I would like to volunteer to test!

Additionally, I have a couple questions...

QUEST #1
Using your mod, is there a way to NOT display products from a sub UNLESS a visitor clicks on that filter/sub?

Lets say I sell medical equipment and parts for repairing medical equipment (because I do!). Here is a quick for instance:
Surgical Products
-OR Tables
--Steris (a manufacturer)
---3080 Series
----3080 SP
-----Steris 3080SP Replacement Parts

That last category (Parts) may have 5,000 products. When a visitor browses, I'd rather not clutter up the display with parts... unless the customer demonstrates that he wants to see Part by clicking on that filter.

So to refine my question, does your mod provide a way to exempt particular sub categories from displaying with all the rest?

QUEST #2
Can your mod be used to overcome the ZC limitation of not allowing products to exist in a category that has a subcategory?

20 May 2016, 9:17 PM
#30
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

OK, I just read Chad's post again and although I confirmed it's exactly what it does, I think I misinterpreted what he had said...

@Feznizzle - both answers are NO. This mod does NOT have products and categories on the same level. Instead, what it does is that it will list all products from that level's subcategories on one page (or multiple paginated pages, of course). BTW, your quest #1 seems like standard Zen Cart... Maybe I'm missing something, dunno...

Anyways... I've tried to draw what this mod would do. At the top of the image, you can see the category structure. The middle right section is what this mod is all about. It keeps the category structure intact, you don't need to have products and subcategories on the same level. It will only display all products that exist in the lower hierarchy level(s).

[img]http://s6.postimg.org/rpgd96h4x/products_below_categories_explained_opt.png[/img]

I hope I'm making sense and that I've (finally) managed to explain what it does...

My site - Pro ZC Help
My portfolio | My plugins

20 May 2016, 10:57 PM
#31
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: How do I list products in sub category with in the parent category?

balihr:

OK, I just read Chad's post again and although I confirmed it's exactly what it does, I think I misinterpreted what he had said...

@Feznizzle - both answers are NO. This mod does NOT have products and categories on the same level. Instead, what it does is that it will list all products from that level's subcategories on one page (or multiple paginated pages, of course). BTW, your quest #1 seems like standard Zen Cart... Maybe I'm missing something, dunno...

Anyways... I've tried to draw what this mod would do. At the top of the image, you can see the category structure. The middle right section is what this mod is all about. It keeps the category structure intact, you don't need to have products and subcategories on the same level. It will only display all products that exist in the lower hierarchy level(s).

[img]http://s6.postimg.org/rpgd96h4x/products_below_categories_explained_opt.png[/img]

I hope I'm making sense and that I've (finally) managed to explain what it does...

Nope, you just over explained it and I'm completely confused now. :P

So basically the category - sub category hierarchy is untouched.

But now on a categories sub-category page is a new "product listing page" that includes all the categories sub-categories products where I can view them without clicking sub-category after sub-category before I actually get to the sub-categories "products listing page".

But if I wanted to view specific products from the categories sub-category page with the new "product listing page" of all the categories sub-categories products I could still click a sub-category which will bring me to the categories sub-category "product listing page" with only that sub-categories products.

Not sure, but I think I'm still completely lost here. :shocking:

20 May 2016, 11:16 PM
#32
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

@rbarbour - uhm... I thought I sent you a copy of the mod earlier... :lookaroun

But, yeah, I think your explanation is spot on. Although I'm having trouble understanding it myself :D I'd say you explained it right. It's quite hard to imagine it, I understand that, I'll see if I can find enough time to setup a live demo in the next few days...

My site - Pro ZC Help
My portfolio | My plugins

20 May 2016, 11:25 PM
#33
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: How do I list products in sub category with in the parent category?

balihr:

@rbarbour - uhm... I thought I sent you a copy of the mod earlier... :lookaroun

But, yeah, I think your explanation is spot on. Although I'm having trouble understanding it myself :D I'd say you explained it right. It's quite hard to imagine it, I understand that, I'll see if I can find enough time to setup a live demo in the next few days...

You did and I'm just getting around to playing with it :lookaroun and it would be a greatly sought after addition to zen cart, I'm loving it.

21 May 2016, 7:25 PM
#34
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How do I list products in sub category with in the parent category?

Thanks for the image and further explanation. That's in line with what I thought you were saying.

Regarding my Q#1, that was poorly put... sorry!

I can use your flow chart to better phrase the question. On the right, the very first position (With Mod, clicked on "parent", browsing parent category). I was hoping there would be a way to only display products from Sub1 and Sub2, unless the visitor clicked on Sub3.

So say Sub1 contains 10 Red Products, Sub2 contains 10 Blue Products, and Sub3 contains 5000 Parts for repairing Blue and Red Products.

But NM. Just ignore that. I dig the idea behind the project, would love to give it a go. I think I read that you wanted those interest in testing to PM you, so I'll do that now.

22 May 2016, 7:29 PM
#35
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,805
Plugin Contributions:
22

Re: How do I list products in sub category with in the parent category?

Feznizzle:

Thanks for the image and further explanation. That's in line with what I thought you were saying.

Regarding my Q#1, that was poorly put... sorry!

I can use your flow chart to better phrase the question. On the right, the very first position (With Mod, clicked on "parent", browsing parent category). I was hoping there would be a way to only display products from Sub1 and Sub2, unless the visitor clicked on Sub3.

This COULD be done, but it would require some custom work. You could add a flag on the categories you want to exclude, and then add the logic to skip those "flagged" categories from displaying it under the sub-cat listing. Just an idea, you might be able to make it even better.

Feznizzle:

But NM. Just ignore that. I dig the idea behind the project, would love to give it a go. I think I read that you wanted those interest in testing to PM you, so I'll do that now.
Replied to your PM - you can get the plugin from my site. I'll be releasing it here in a couple days, just need to write some documentation for it.

My site - Pro ZC Help
My portfolio | My plugins

24 May 2016, 3:56 PM
#36
sarahl avatar

sarahl

Zen Follower

Join Date:
May 2004
Location:
UK
Posts:
471
Plugin Contributions:
0

Re: How do I list products in sub category with in the parent category?

I too would like to test your plugin as well - I believe this was something that I was looking for a while back - but didn't find your thread - sorry about that - if you are still wanting testers please let me know

I did look at your website for a copy of the plugin but couldn't find it

FOUND IT!! thank you looks exceedingly useful!!!

24 May 2016, 8:14 PM
#37
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I list products in sub category with in the parent category?

Took a gander at some of the involved code to apply this as I think others have been looking such that when looking at a category that has sub-categories it is possible to "add" a product to that category and display both the sub-categories and the product(s) in the center screen.

Could be applied as a "plugin" such that current files would not require modification, but the whole thing could be additional code.

Primarily, includes/modules/pages/index/header_php.php currently evaluates the current category_id (this was I think while looking at ZC 1.5.5 code). If the current category_id has product listed in it then just the products designation is sent along to be processed by downstream code. Currently if a category has multiple categories with it then that results in a page style to be displayed, if that category doesn't have anything further associated with it then it's treated as an empty product display.

Anyways, with a little further "care" the evaluation could go if there are product, then evaluate if there are also categories. Then direct to a "template" file that handles display of both. I would (as I believe I have in other similar threads) still keep the "category" structure as originally coded but then link the product desired to be displayed in this "merged" category display. That way the pricing structure remains untouched and the product is just simply "managed" as to where it should be displayed. Of course then comes in things like sort order, sequencing, percentage of each category/product to display, etc... but guess it's a start. :P

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

2 Dec 2018, 7:30 PM
#38
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: How do I list products in sub category with in the parent category?

I apologize for resurrecting a 2 year old thread, but I'm working on this problem now so figured I would post some of the solutions I have.

As a rehash, the goal is that when clicking on a category that contains sub categories, the category page will at a minimum display all the products from the sub categories (it might also display the sub category names, and other things.)

From a page load perspective you could argue this is poor practice. From a user experience perspective I would argue this is very helpful - especially if the subcategories are numerous and the number of products in each subcategory is small.

Most users now anticipate being able to shop/view this way and naturally want to scroll due to the UI of mega sites such as Pinterest, Instagram, Facebook, etc.

Solutions I have Found:

  1. One solution is built into the Tableau 1 template by Numinix. Pros: it also includes additional sort options like 'most popular'. Cons: it isn't standalone, it impacts core files such as modules/pages/index/header.php and more (plus requires a lot of extra files)

  2. In this thread: https://www.zen-cart.com/showthread.php?83008-Display-all-categories-products-on-one-page yellow1912 posted a download. This sort of works, but the sql code is incorrect and causes all products (of the entire store) to load. This is fixable with some sql changes, but not really worth going into in this post.

  3. Balihr mentioned in this thread he had a solution, but it wasn't posted so you can message him directly.

  4. The easiest solution I found is to use the existing stuff of Zen-Cart that already does this. That would be the new products, featured products, and specials modules that appear on category and subcategory pages. Pros: pretty straightforward and using similar structure to existing code Cons: pagination isn't built in.

Here are the quick instructions without utilizing Admin switches. I'm using responsive_classic template and using the module name all_cats_all_products. These instructions have been written as though you have some knowledge of navigating the Zen-Cart files.

  1. Add to includes/filenames.php define('FILENAME_ALL_CATS_ALL_PRODUCTS', 'all_cats_all_products.php');

  2. Create the new file 'includes/templates/responsive_classic/tpl_modules_all_cats_all_products.php' this will mirror 'includes/templates/template_default/tpl_modules_whats_new.php' (or your already custom version) with some small changes. You will need to adjust if you have already customized this file.

  3. Make the file contents:

<?php
/**
 * Module Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_modules_all_cats_all_products.php
 */
  include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_ALL_CATS_ALL_PRODUCTS));
?>

<!-- bof: all_cats_all_products -->
<div class="centerBoxWrapper" id="allcatsallproducts">
<?php
  require($template->get_template_dir('tpl_columnar_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display.php');
?>
</div>
<!-- eof: all_cats_all_products -->
  1. Create the new file 'includes/modules/all_cats_all_products.php' this will mirror 'includes/modules/new_products.php' (or your already custom version) with some small changes. You will need to adjust if you have already customized this file.

  2. Note - in an effort to match the styling of featured products, new products, and specials, and minimize database changes, this file still pulls some settings from admin that correlate to new_products. For instance it uses the new products columns per row setting, etc.

  3. Make the file contents:

<?php
/**
 * all_cats_all_products.php module
 *
 * @package modules
 * @copyright Copyright 2003-2008 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: all_cats_all_products.php 8730 2008-06-28 01:31:22Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

// initialize vars
$categories_products_id_list = '';
$list_of_products = '';
$all_cats_all_products_query = '';

if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($all_cats_all_products_category_id) || $all_cats_all_products_category_id == '0') ) {
  $all_cats_all_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and   p.products_status = 1 ";
} else {
  // get all products and cPaths in this subcat tree
  $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0);

  if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
    // build products-list string to insert into SQL query
    foreach($productsInCategory as $key => $value) {
      $list_of_products .= $key . ', ';
    }
    $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

    $all_cats_all_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                  p.products_date_added, p.products_price, p.products_type, p.master_categories_id,p.products_calories, p.products_netcarbs, p.products_smartdietcount
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and p.products_status = 1
                           and p.products_id in (" . $list_of_products . ")";
  }
}

if ($all_cats_all_products_query != '') $all_cats_all_products = $db->ExecuteRandomMulti($all_cats_all_products_query, 5000);

$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';

$num_products_count = ($all_cats_all_products_query == '') ? 0 : $all_cats_all_products->RecordCount();

// show only when 1 or more
if ($num_products_count > 0) {
  if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS == 0 ) {
    $col_width = floor(100/$num_products_count);
  } else {
    $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS);
  }

  while (!$all_cats_all_products->EOF) {
    $products_price = zen_get_products_display_price($all_cats_all_products->fields['products_id']);
    if (!isset($productsInCategory[$all_cats_all_products->fields['products_id']])) $productsInCategory[$all_cats_all_products->fields['products_id']] = zen_get_generated_category_path_rev($all_cats_all_products->fields['master_categories_id']);

    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($all_cats_all_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($all_cats_all_products->fields['products_id']), 'cPath=' . $productsInCategory[$all_cats_all_products->fields['products_id']] . '&products_id=' . $all_cats_all_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $all_cats_all_products->fields['products_image'], $all_cats_all_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($all_cats_all_products->fields['products_id']), 'cPath=' . $productsInCategory[$all_cats_all_products->fields['products_id']] . '&products_id=' . $all_cats_all_products->fields['products_id']) . '">' . $all_cats_all_products->fields['products_name'] . '</a><br />' . $products_price);

    $col ++;
    if ($col > (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS - 1)) {
      $col = 0;
      $row ++;
    }
    $all_cats_all_products->MoveNextRandom();
  }

      $title = '<h2 class="centerBoxHeading">' . $current_categories_name . '</h2>';
}
?>
  1. Copy includes/templates/template_default/tpl_index_categories.php (or your already custom version) and save as includes/templates/responsive_classic/tpl_index_categories.php

  2. In tpl_index_categories.php insert the following where you want the products to display on the category page:

<?php require($template->get_template_dir('tpl_modules_all_cats_all_products.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_all_cats_all_products.php'); ?>
  1. If you want this to appear on the index page do the same for tpl_index_default.php I would suggest not doing that, unless you have a very small number of products in which case you should just feature all the products in the featured products module and set that to appear on the home page.
2 Dec 2018, 7:54 PM
#39
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: How do I list products in sub category with in the parent category?

Looks like the code for the second file (includes/modules/all_cats_all_products.php_ should be what I posted below instead. I attempted to change all instances of 'new_products' to 'all_cats_all_products' but my changes caused all products to appear, not just subcategories. This code could be buttoned up some, but will suffice.

<?php/**
 * new_products.php module
 *
 * @package modules
 * @copyright Copyright 2003-2008 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: new_products.php 8730 2008-06-28 01:31:22Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}


// initialize vars
$categories_products_id_list = '';
$list_of_products = '';
$new_products_query = '';


$display_limit = zen_get_new_date_range();


if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) {
  $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and   p.products_status = 1 ";
} else {
  // get all products and cPaths in this subcat tree
  $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0);


  if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
    // build products-list string to insert into SQL query
    foreach($productsInCategory as $key => $value) {
      $list_of_products .= $key . ', ';
    }
    $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma


    $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                  p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and p.products_status = 1
                           and p.products_id in (" . $list_of_products . ")";
  }
}


if ($new_products_query != '') $new_products = $db->ExecuteRandomMulti($new_products_query, 5000);


$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';


$num_products_count = ($new_products_query == '') ? 0 : $new_products->RecordCount();


// show only when 1 or more
if ($num_products_count > 0) {
  if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS == 0 ) {
    $col_width = floor(100/$num_products_count);
  } else {
    $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS);
  }


  while (!$new_products->EOF) {
    $products_price = zen_get_products_display_price($new_products->fields['products_id']);
    if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev($new_products->fields['master_categories_id']);


    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a><br />' . $products_price);


    $col ++;
    if ($col > (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS - 1)) {
      $col = 0;
      $row ++;
    }
    $new_products->MoveNextRandom();
  }


  if ($new_products->RecordCount() > 0) {
    if (isset($new_products_category_id) && $new_products_category_id != 0) {
      $category_title = zen_get_categories_name((int)$new_products_category_id);
      $title = '<h2 class="centerBoxHeading">' . $category_title . '</h2>';
    } else {
      $title = '<h2 class="centerBoxHeading">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) . '</h2>';
    }
    $zc_show_new_products = true;
  }
}
?>