:: EDIT ::
Okay here's what I did and so far it seems to work:
The $products array gets defined in a code snippet at the bottom of
$xcart_dir/products.php. I moved that code snippet into a new file
$xcart_dir/products_by_catid.php and modified products.php to include the new file. Now I have the freedom to load a $products array any time I want. I simply set $cat then include products_by_catid.php. After I verified that this small change worked (i.e. hit reload and page still there), I then modified products.php to cycle through the $subcategories array and, for each subcategory, grab the products list and store it in a "products" field.
What would make this mod really nice would be a simple way to enable/disable it from the admin console. Any Ideas?
Also, the code snippet that I added to products.php could just as easily be placed in
$xcart_dir/home.php instead, which may actually be a more appropriate place for it.
Feeback appreciated.
Thanx
-D
PS: Oh, and it would be nice to have another mod that would add the subcats for the subcats
I might try that one later.
---
Here's a small test snippet and the file changes for the mod:
Test Snippet To Try In: $xcart_dir/skin1/customer/main/subcategories.tpl
Code:
{if $subcategories}
<ul>
{foreach from=$subcategories item=subcat}
[*]{$subcat.category|escape}
<ul>
{foreach from=$subcat.products item=subproduct}
{if $subproduct}
[*]{$subproduct.product|escape}
{/if}
{/foreach}
[/list] {/foreach}
[/list]{/if}
Create New File: $xcart_dir/products_by_catid.php
Code:
<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2006 Ruslan R. Fazliev <rrf@rrf.ru> |
| All rights reserved. |
+-----------------------------------------------------------------------------+
| PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
| |
| THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
| FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
| AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
| PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
| CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
| COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
| (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
| LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
| AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
| OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
| THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2006 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\*****************************************************************************/
#
# $Id: products.php,v 1.12 2006/01/11 06:55:57 mclap Exp $
#
# Navigation code
#
if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }
# DavidPFarrell - This code was copied, unaltered, from $xcart_dir/products.php
#
# Get products data for current category and store it into $products array
#
$old_search_data = $search_data["products"];
$old_mode = $mode;
$search_data["products"] = array();
$search_data["products"]["categoryid"] = $cat;
$search_data["products"]["search_in_subcategories"] = "";
$search_data["products"]["category_main"] = "Y";
$search_data["products"]["category_extra"] = "Y";
$search_data["products"]["forsale"] = "Y";
if(!isset($sort))
$sort = $config["Appearance"]["products_order"];
if(!isset($sort_direction))
$sort_direction = 0;
$mode = "search";
include $xcart_dir."/include/search.php";
$search_data["products"] = $old_search_data;
$mode = $old_mode;
if (!empty($active_modules["Subscriptions"])) {
include $xcart_dir."/modules/Subscriptions/subscription.php";
}
# /DavidPFarrell
?>
Modify File: $xcart_dir/products.php
Code:
<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2006 Ruslan R. Fazliev <rrf@rrf.ru> |
| All rights reserved. |
+-----------------------------------------------------------------------------+
| PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
| |
| THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
| FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
| AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
| PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
| CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
| COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
| (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
| LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
| AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
| OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
| THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2006 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\*****************************************************************************/
#
# $Id: products.php,v 1.12 2006/01/11 06:55:57 mclap Exp $
#
# Navigation code
#
if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }
if ($config["General"]["disable_outofstock_products"] == "Y") {
$avail = ($config["General"]["unlimited_products"] =="N")? " AND $sql_tbl[products].avail>0 " : "";
$current_category["product_count"] = func_query_first_cell ("SELECT COUNT(*) FROM $sql_tbl[products], $sql_tbl[products_categories] WHERE $sql_tbl[products].productid=$sql_tbl[products_categories].productid AND $sql_tbl[products].forsale='Y' $avail AND $sql_tbl[products_categories].categoryid='$cat'");
if (is_array($subcategories)) {
foreach($subcategories as $k=>$v) {
$subcategories[$k]["product_count"] = func_query_first_cell ("SELECT COUNT(*) FROM $sql_tbl[products], $sql_tbl[products_categories] WHERE $sql_tbl[products].productid=$sql_tbl[products_categories].productid AND $sql_tbl[products].forsale='Y' $avail AND $sql_tbl[products_categories].categoryid='$v[categoryid]'");
}
$smarty->assign("subcategories",$subcategories);
}
}
if ($active_modules["Advanced_Statistics"] && !defined("IS_ROBOT"))
include $xcart_dir."/modules/Advanced_Statistics/cat_viewed.php";
# DavidPFarrell - Add a "products" field to each subcategory containing the array of products for that subcategory
if (is_array($subcategories))
{
$_oldcat = $cat;
foreach ($subcategories as $_catid => $_subcat)
{
if (!empty($_catid))
{
$cat = $_catid;
$products = "";
include $xcart_dir."/products_by_catid.php";
if (is_array($products))
{
$subcategories[$_catid]["products"] = $products;
}
}
}
$smarty->assign("subcategories",$subcategories);
$cat = $_oldcat;
}
# /DavidPFarrell
include $xcart_dir."/products_by_catid.php";
$smarty->assign("products",$products);
$smarty->assign("navigation_script","home.php?cat=$cat&sort=$sort&sort_direction=$sort_direction");
?>
=== Original Post ===
I could really use a response to this if anyone is out there?
It looks like "products.php" finds the product list via a specialized search. I was thinking we could do a similar thing within the loop that cycles through the sub-cats.
I was also thinking of trying to modify home.php and/or categories.php and/or products.php to create "subcat_products[subCatId]" (and possibly subcat_subcats[])
My concern with these is the extra function calls or includes changing variables that aren't needed for this mod but might be needed by other pages.
Ideas?