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....ts-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:
Code:
<?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 -->
4. 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.
5. 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.
5. Make the file contents:
Code:
<?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>';
}
?>
6. 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
7. In tpl_index_categories.php insert the following where you want the products to display on the category page:
Code:
<?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'); ?>
8. 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.
Bookmarks