X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   How do I display all subcategories along with all products (https://forum.x-cart.com/showthread.php?t=19730)

pwd88 02-04-2006 05:48 PM

How do I display all subcategories along with all products
 
How do I display all subcategories along with all products under each subcategory on one page, here is what I want to do:
1 root category, has 2 subcategories, when customer clicks on root category, the subcategories.tpl displays 2 lines listed 2 subcategories, which is pretty ugly, I want it to dispaly like the following:
subcategory1
product1 under subcategory1
product2 under subcategory1
product3 under subcategory1
....
subcategory2
product1 under subcategory2
product2 under subcategory2
.....

Thanks in advance if you can point me into a right direction

btomasie 02-28-2006 08:25 AM

TTT. I am looking for the same exact thing. Did anyone contact you prvately by chance with a aolution? Or were you able to find something in another threads that solved this for you? Thanks!

Brian

DavidPFarrell 06-21-2006 08:37 PM

:: 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?

mikalou 08-06-2007 01:54 PM

Re: How do I display all subcategories along with all products
 
I needed to add
Code:

$products = "";
after
Code:

$smarty->assign("subcategories",$subcategories);
$cat = $_oldcat;

in your products.php custom routine.
Here's why:
If the category has no products but has multiple subcategories, and if the last category of those subcategories has products, the page would display these products twice. Once within the sub category and once underneath the category.

RobinBraves 10-25-2007 09:41 AM

Re: How do I display all subcategories along with all products
 
Do you guys have a sample URL I could take a look at to see what this would look like?

RobinBraves 10-25-2007 10:17 AM

Display SubCategory titles with products
 
I have searched through the forum and could not find anyone who has been able to implement this:

SubCategory Title
-------------------------------------------
product1 product2

product3 product4


SubCategory Title2
-------------------------------------------
product1 product2

product3 product4



Right now, it only shows products in the root category with all the SubCategory Titles above.

chamberinternet 10-26-2007 04:11 AM

Re: Display SubCategory titles with products
 
Do you mean on the crumb trail ?

mikalou 10-26-2007 09:45 AM

Re: How do I display all subcategories along with all products
 
Here's a store that utilizes this custom mod: View Example Live Store
The store owner hasn't added many products yet but you should still be able to get a good idea of how it looks.

RobinBraves 10-26-2007 09:48 AM

Re: How do I display all subcategories along with all products
 
Do you have the mod instructions for installation? I am using 4.1.8 and it does not apear to work for me with the instructions above.

RobinBraves 10-26-2007 10:06 AM

Re: Display SubCategory titles with products
 
No, on the actual page.

I need it to appear like this sample:
http://www.jackmansfabrics.com/Bridal-Fabrics-p-1-c-294.html


All times are GMT -8. The time now is 11:12 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.