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

mikalou 10-26-2007 10:37 AM

Re: How do I display all subcategories along with all products
 
That store that I linked to is 4.1.8 and I used the instructions that were listed in a post above mine with the one modification that I mentioned in one of my other posts.

designtheweb 10-26-2007 03:29 PM

Re: How do I display all subcategories along with all products
 
I have tried this one and it works well except for one thing, it is only showing up the products of the last category not in other categories with products on the same level.

Any ideas?

Thanks.

MoonDog 10-27-2007 05:27 PM

Re: Display SubCategory titles with products
 
I just created something similar to what you need from an old posting a couple of days ago.
I just modified it a little to make it work on v4.1.8

First of all, kudos to the creator and all those that contributed to the original mod.

Start by opening up the xcart/include/categories.php file.
And find these lines of code: (it's at the bottom)
Code:


if (!empty($subcategories))
$smarty->assign("subcategories", $subcategories);
$smarty->assign("cat", $cat);
?>

And right above those lines of code add:
Code:


//Subcategories in menu
function sort_by_order_by($a, $b)
{
    if ($a['order_by'] == $b['order_by']) {
      return 0;
  }
  return ($a['order_by'] < $b['order_by']) ? -1 : 1;
}
function func_getallsubcat()
{
$raj =func_get_categories_list("", true, "all");
$raj1=$raj['all_categories'];
usort($raj1 ,"sort_by_order_by");
$ll=array();
foreach ($raj1 as $k=>$val)
{
if($val['parentid']!="0")
{
$ll[$val['parentid']][]=$val;
}
}
return $ll;
}
$smarty->assign("allsubcategories", func_getallsubcat());
//Subcategorie in menu - end


Now, replace your skin1/customer/categories.tpl with this modified categories.tpl

Code:


{* $Id: categories.tpl,v 1.26 2005/11/17 06:55:37 max Exp $ *}
{* modified *}
<div id="sidenavcontainer">
{capture name=menu}
{if $active_modules.Fancy_Categories ne ""}
{include file="modules/Fancy_Categories/categories.tpl"}
{assign var="fc_cellpadding" value="0"}
{else}
{if $config.General.root_categories eq "Y"}
<ul id="mainmenu">
{foreach from=$categories item=c}
{if $cat eq $c.categoryid || $current_category.parentid eq $c.categoryid}
<li><h3><a class="current" href="home.php?cat={$c.categoryid}">{$c.category}</a></h3></li>
{else}
<li><h3><a href="home.php?cat={$c.categoryid}">{$c.category}</a></h3></li>
{/if}
{assign var=in value=$c.categoryid}
{* CONDITIONAL DROP DOWN ITEMS FROM TOP CATEGORY *}
<ul id="submenu">
{foreach from=$allsubcategories.$in item=c }
{if $cat eq $c.categoryid}
<li><h4><a class="current" href="home.php?cat={$c.categoryid}">{$c.category}</a></h4></li>
{else}
<li><h4><a href="home.php?cat={$c.categoryid}">{$c.category}</a></h4></li>
{/if}
{/foreach}
</ul>
{* /CONDITIONAL *}
{/foreach}
{else}
{foreach from=$subcategories item=c key=catid}
<li><a href="home.php?cat={$catid}">{$c.category}</a></li>
{/foreach}
{/if}
</ul>
{/if}
</div>
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding}

And the last thing you need to do is copy the following code and add it to the bottom of your skin1.css file
Code:


/**
* sidenavcontainer is 181px wide and a minimum of 400px high
* It has a little padding top and bottom as well
* Modify it to suit your layout
*/
html, body, ul, ol, li, p,
h1, h2, h3, h4, h5, h6,
form, fieldset, a {
    list-style-type: none;
    margin: 0;
    padding: 0;
    border: 0;
}
/*#sidenavcontainer {
    padding:200px 0 10px 0;
    PADDING-LEFT: 20px;
    PADDING-BOTTOM: 10px;
    width:181px;
    min-height:0px;
    float:left;
}
*/
h3{    /* PRODUCT CATEGORIES */
    padding:200;
    margin:100;
    font-size:11px;
    font-style:normal;
    font-weight:normal;
}
#sidenavcontainer h3 {
    margin:0 0 0 0px;
    padding:0px;
}
h4{    /* PRODUCT SUB-CATEGORIES */
    padding:0;
    margin:0;
    font-size:11px;
    font-style:normal;
    font-weight:normal;
}
#sidenavcontainer h4 {
    margin:0 0 0 20px;
    padding:20;
    padding-bottom:2px;
}
#sidenavcontainer a {
    color:#000000;
    text-decoration:none;
}
#sidenavcontainer a:hover {
    color:#FF0000;
    text-decoration:none;
}
#sidenavcontainer .current {
    color:#3333FF;
}


And that's it.

- MoonDog -

RobinBraves 10-28-2007 07:15 AM

Re: Display SubCategory titles with products
 
I followed the steps you gave, MoonDog, and I don't see a change: http://sentimentalist.net/store/greeting-cards-c-1.html

I even ran cleanup.php to make sure my temp files were cleaned out.

Did I do something wrong?

andyweb 10-28-2007 10:53 AM

Re: Display SubCategory titles with products
 
Hi MoonDog,

Thanks so much for this post.
I am also having the same problem.

I followed all the instructions, but still cant get the products to display in the menu.
It now displays the subcategories.

MoonDog 10-28-2007 12:31 PM

Re: Display SubCategory titles with products
 
1 Attachment(s)
RobinBraves,

Unfortunately you won't be able to use this code on your site :( . I went to your site (great site by the way) and noticed that you are using javascript code for your current menu. Since you have a customized menu you will have to remove and modify your code in order for this to work. By the way, on your site, the last three items of your custom menu doesn't work in Internet Explorer 6. You can't see any of the text unless you hover over them. It works OK in Firefox though.

andyweb,

I've copied the code from this post and followed my exact instructions to see if there was a typo or bad code. I re-installed it and tested it and it still works like a charm. I've attached a thumbnail so you can see what it is suppose to look like.
You might try re-doing the installation again in case you made a previous mistake.

- MoonDog -

RobinBraves 10-28-2007 02:16 PM

Re: Display SubCategory titles with products
 
Not sure if this is what I will need. Does this make the actual page in the middle show the subcategory titles with all their products listed below?

Example:
-------------------------------------------------------
Celebration
-------------------------------------------------------
product1 product2 product3

product4 product5

------------------------------------------------------
Gratitude
------------------------------------------------------
product1 product2 product3

------------------------------------------------------
Seasonal
------------------------------------------------------
product1 product2 product3

product4 product5 product6

product7

MoonDog 10-28-2007 03:37 PM

Re: Display SubCategory titles with products
 
RobinRaves,

Quote:


Does this make the actual page in the middle show the subcategory titles with all their products listed below?


My mistake:oops: . I thought you needed a categories menu with the listed sub-categories on the left side of the page.

I did post some code a while back that deals with sub-categories and sub-sub-categories in the middle of the page, but it used graphics and text. I'm not sure if this is what you need, but click here to go there. I've placed two thumbnail images on the bottom of that post so you can see if that is what you need.

- MoonDog -

RobinBraves 10-28-2007 08:19 PM

Re: Display SubCategory titles with products
 
No problem, MoonDog. I really do appreciate your help. I took a look at that other forum and it is not what I need.

What I need is seen here:
http://www.jackmansfabrics.com/Bridal-Fabrics-p-1-c-294.html

This page shows a SubCategory Heading with the products below and then ANOTHER SubCategory Heading below that and its products below and so forth.

By default, x-cart just shows the subcategories (with or without images) but not the products. You actually have to click on the subcategory to see the products of just that subcategory.

I need for my customer to see all the subcategory headings with the corresponding products below each.

I hope that makes sense. I saw 1 thread about this, but it was not made for 4.1.8 or newer.

I'm kinda bummed out. Good news is... I think I am going to use this mod anyway because the menu I have is "jumpy" and I'm not a huge fan.

RobinBraves 10-29-2007 09:08 PM

Re: How do I display all subcategories along with all products
 
Quote:

Originally Posted by mikalou
That store that I linked to is 4.1.8 and I used the instructions that were listed in a post above mine with the one modification that I mentioned in one of my other posts.


Okay, I followed the instructions exactly and also made the update that you posted. Here is what my page looks like:

http://sentimentalist.net/store/greeting-cards-c-1.html

Any suggestions? What could I be doing wrong/

MoonDog 11-03-2007 02:27 PM

Re: How do I display all subcategories along with all products
 
1 Attachment(s)
RobinBraves,

Looks like you've done everything correct. All you need to do now is to convert the sample code in subcategories.tpl to something that will read your data and place it formated on the page.

If you need some code to get you going I've gathered some code from various different threads and altered the subcategories.tpl file to show the output in icons and text. It is also hyperlinked so that you can click on the icon and the text. I've attached a thumbnail so you can see what it looks like.

First, add this code to the end of your skin1.css file:
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 33%;
      PADDING-LEFT: 5px;
}

Then replace the code from <table> to </table> in the skin1/customer/main/subcategories.tpl file with the code below:
Code:


<table cellspacing="5" width="100%" border="2">
{foreach from=$subcategories item=subcat}
<tr>
<td class="ColumnTitles" valign="top"><a title="{$subcat.description}" <a href="home.php?cat={ $subcat.categoryid }"><img src="{if $subcat.icon_url}{$subcat.icon_url}{else}{$xcart_web_dir}/default_image.gif{/if}" alt="" /><br>
<font class="ItemsList">{ $subcat.category|escape }</font></a>
</td></tr>
{foreach from=$subcat.products item=subproduct}
{if $tmp is div by 3}
<tr><td colspan="3"></td></tr>
<tr valign="top">
{/if}
{ if $tmp and $first_subproduct ne "Y" }
{assign var="tmp" value=0}
{assign var="first_subproduct" value="Y"}
{/if}
{if subproduct}
<td class="ColumnTitles" valign="top"><a title="{$subproduct.description}" <a href="product.php?productid={$subproduct.productid}&amp;cat={ $subproduct.productid }&amp;cat={$cat}&amp;page={$navigation_page}"><img src="{if $subproduct.tmbn_url}{$subproduct.tmbn_url}{else}{$xcart_web_dir}/default_image.gif{/if}" alt="" /><br>
{$subproduct.product|escape}
{/if}
<br>
{assign var="tmp" value=$tmp+1}
{/foreach}
{if $tmp is not div by 3}
{assign var="tmp" value=3}
{/if}
{/foreach}
</tr>
</td>
</table>

The above code produces three columns.
If you need to change it to two column then change these 2 lines of code in subcategories.tpl:
Code:


{if $tmp is div by 3}
<tr><td colspan="3"></td></tr>

For two columns you need to replace both number 3's to 2
And for 4 columns you need to replace them to 4

And also at these 2 lines of code:
Code:

{if $tmp is not div by 3}
{assign var="tmp" value=3}
{/if}


You also need to change the percentage code you placed in your skin1/skin1.css file.

Example: for 2 columns it's 50%
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 50%;
      PADDING-LEFT: 5px;
}

Example: for 4 columns it's 25%
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 25%;
      PADDING-LEFT: 5px;
}


Unfortunately I've been so busy, I didn't have much time to test it out completely, but it's a start to get you going. You might have to change the table code or the css code to what you need. I also didn't work on the sort order (it's ordered alphabetically), it's different than the sort order on the menu (see the thumbnail). You can change the position order in the categories section of the admin side.
Anyway, hope this will get you going.

- MoonDog -

designtheweb 11-07-2007 11:36 AM

Re: How do I display all subcategories along with all products
 
Where exactly in the subcategories.tpl does the following code go. I've tried it in a few different places an end up getting a whole load of offset text which outlines the contents of the subcategories but no actual products.

Thanks.

{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}

RobinBraves 11-07-2007 03:39 PM

Re: How do I display all subcategories along with all products
 
You are a genius! Sorry for taking so long to get back. This worked and I will need to make some css and table adjustments, but that will be easy to do.

I really appreciate this.. I can actually feel stress relieving off of me.

MoonDog 11-09-2007 09:43 PM

Re: How do I display all subcategories along with all products
 
RobinBraves,
Glad to see you got it working and not as stressed anymore. :-)

designtheweb,
Quote:


Where exactly in the subcategories.tpl does the following code go. I've tried it in a few different places an end up getting a whole load of offset text which outlines the contents of the subcategories but no actual products.

The test code that you are using in the subcategories file is just logic. All that you would be getting is like you described; offset text which outlines the contents of the subcategories but no actual products.
Just follow the instructions I posted previously without this test code and you will see the products displayed instead of text.

- MoonDog -

Chrisb 02-12-2008 07:20 PM

Re: How do I display all subcategories along with all products
 
This code seems to change the layout of the individual products. is there a way to keep the individual products layout but have the products under the subcategories?

MythNReality 03-24-2008 07:58 PM

Re: Display SubCategory titles with products
 
this is EXACTLY what I wanted. Thank you for sharing. Great works...hope I can get the subcategories show as subcategories. Right now, they all show as categories...can't tell which is subcategories. Had to play with it to get it work... ;-(

bitstream 05-09-2008 01:45 AM

Re: Display SubCategory titles with products
 
Works like a charm, thank you for this.

Scotty85 07-03-2008 02:26 PM

Re: Display SubCategory titles with products
 
Yep, exactly what I wanted. Thanks!!

Scotty

Scotty85 07-03-2008 08:37 PM

Re: Display SubCategory titles with products
 
Just out of curiosity... I've looked all over the forums but can't find what I'm looking for.....

Is there a way to have only the main cats show and expand down to show the subs only in that cat once it's clicked?

bitstream 07-03-2008 11:05 PM

Re: Display SubCategory titles with products
 
Fancy Categories does that but not expand, only popup. Use x-cart demo and you will see Fancy Categories in action.

Kiwami 10-23-2008 07:55 AM

Re: Display SubCategory titles with products
 
Don't mean to bump this up but thanks very much moondog, i really needed this :)

davidsaldana 12-17-2008 10:52 AM

Re: Display SubCategory titles with products
 
Quote:

Originally Posted by Scotty85
Just out of curiosity... I've looked all over the forums but can't find what I'm looking for.....

Is there a way to have only the main cats show and expand down to show the subs only in that cat once it's clicked?


Did you ever figure out how to do this...I am looking to do the same.

rshandel 04-13-2009 04:57 AM

Displaying products in subcategory on category page
 
I having trouble figuring out how to display all products in all the subcategories on the category page like this:

subcat name1
product 1
product 2

subcat name2
product 1
product 2

etc...

I would only like to do this on certain categories (I can use an if statement and include a different template) or display like above only for categories that have subcategories.

Any help would be greatly appreciated.

Thanks

Victor D 04-13-2009 06:26 AM

Re: Displaying products in subcategory on category page
 
1. home.php
Code:

define('OFFERS_DONT_SHOW_NEW',1);
require "./auth.php";

require $xcart_dir."/include/categories.php";

if ($active_modules["Manufacturers"])
    include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";

//mod
$p_flag = count($products)>0;
$s_total = 0;
if (!empty($subcategories)){
    foreach ($subcategories as $ss){
        $old_search_data = $search_data["products"];
        $old_mode = $mode;

        $search_data["products"] = array();
        $search_data["products"]["categoryid"] = $ss['categoryid'];
        $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;
        $s_products[$ss['categoryid']] = $products;
        $s_total += count($products);
    }
        $smarty->assign("s_products", $s_products);
        $smarty->assign("s_total", $s_total);
        if (!$p_flag) $products = array();
}
//mod ends

if (!empty($cat))
    include "./products.php";

if (empty($products))
    include "./featured_products.php";

if ($active_modules["Bestsellers"])
    include $xcart_dir."/modules/Bestsellers/bestsellers.php";

...


2. skin1/customer/main/subcategories.tpl
Code:

{* $Id: subcategories.tpl,v 1.55.2.4 2008/07/15 12:07:40 ferz Exp $ *}
{if $active_modules.Bestsellers ne "" and $config.Bestsellers.bestsellers_menu ne "Y"}
<p />
{include file="modules/Bestsellers/bestsellers.tpl"}
{/if}
<p />
{if $active_modules.Special_Offers}
{include file="modules/Special_Offers/customer/category_offers_short_list.tpl"}
{/if}
{if ($navigation_page eq "")||($navigation_page eq "1")}{$current_category.description}<p />{/if}
{capture name=dialog}
{assign var="tmp" value="0"}
{foreach from=$subcategories item=c key=catid}
{if $c.category}{assign var="tmp" value="1"}{/if}
{/foreach}
{if $subcategories}
<table cellspacing="5" width="100%">
{foreach from=$subcategories item=subcat}
<tr>
{if $tmp and $first_subcat ne "Y"}

{*mod starts*}
{capture name=hidd}
{count value=$subcategories assign=rowspan1}
{/capture}
    <td valign="top" rowspan="{$rowspan1+$s_total}"><img src="{if $current_category.icon_url}{$current_category.icon_url|amp}{else}{$xcart_web_dir}/image.php?id={$cat}&amp;type=C{/if}" alt="{$current_category.category|escape}"{if $current_category.image_x} width="{$current_category.image_x}"{/if}{if $current_category.image_y} height="{$current_category.image_y}"{/if} /></td>
{assign var="first_subcat" value="Y"}
{/if}
    <td class="SubcatTitle"><a href="home.php?cat={ $subcat.categoryid }"><font class="ItemsList">{ $subcat.category|escape }</font></a><br /></td>
    <td class="SubcatInfo">{if $config.Appearance.count_products eq "Y"}
{if $subcat.product_count}{ $subcat.product_count } {$lng.lbl_products}
{elseif $subcat.subcategory_count}{ $subcat.subcategory_count } {$lng.lbl_categories|lower}
{/if}
    {/if}</td>
</tr>
{if $s_products[$subcat.categoryid] ne ''}
{foreach from=$s_products[$subcat.categoryid]  item=sprods}
<tr>
<td colspan="3">{$sprods.product}</td>
</tr>
{/foreach}
{/if}
{*mod ends*}

{/foreach}
</table>
{/if}
{if $tmp and $products ne "" }
<br clear="left" />
<hr size="1" noshade="noshade" />
{/if}
{if $products}
{if $sort_fields}
<div align="right">{include file="main/search_sort_by.tpl" sort_fields=$sort_fields selected=$search_prefilled.sort_field direction=$search_prefilled.sort_direction url="home.php?cat=`$cat`&"}</div>
{/if}
{if $total_pages gt 2}
<br />
{ include file="customer/main/navigation.tpl" }
{/if}
<hr size="1" width="100%" />
{include file="customer/main/products.tpl" products=$products}
{/if}
...


rshandel 04-13-2009 08:21 AM

Re: Displaying products in subcategory on category page
 
Thanks so much for the mod Victor! Worked like a charm!!!

I added a link to the products display in subcategories.tpl:

Change this:

<td colspan="3">{$sprods.product}</td>

to this:

<td colspan="3"><a href="product.php?productid={$sprods.productid}">{ $sprods.product}</a></td>
Thanks again Victor. You Rock!!!

1CNS 04-27-2009 09:53 PM

Re: Displaying products in subcategory on category page
 
This looks like a great mod, but in 4.2.1, subcategories.tpl looks so different than the version above, that I didn't even attempt this mod. Anyone know how to adjust this to 4.2.1?

Victor D 05-22-2009 08:02 AM

Re: Displaying products in subcategory on category page
 
For 4.2.1 (home.php code is the same with one from the post#2)

skin1/customer/main/subcategories_t.tpl:
Code:

{*
$Id: subcategories_t.tpl,v 1.6 2008/11/25 15:57:54 max Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
{foreach from=$subcategories item=subcategory}

  <div class="subcategories" style="min-width: {$subcat_div_width}px; width: {$subcat_div_width}px; height: {$subcat_div_height}px; min-height: {$subcat_div_height}px;">
    {if $subcategory.is_icon}
      <a href="home.php?cat={$subcategory.categoryid}"><img src="{$subcategory.icon_url|amp}" alt="{$subcategory.category|escape}" width="{$subcategory.image_x}" height="{$subcategory.image_y}" /></a>
    {else}
      <img src="{$ImagesDir}/spacer.gif" alt="" width="1" height="{$subcat_img_height}" />
    {/if}
    <br />
    <a href="home.php?cat={$subcategory.categoryid}">{$subcategory.category|escape}</a><br />
    {if $config.Appearance.count_products eq "Y"}
      {if $subcategory.product_count}
        {$subcategory.product_count} {$lng.lbl_products|lower}
      {elseif $subcategory.subcategory_count}
        {$subcategory.subcategory_count } {$lng.lbl_categories|lower}
      {/if}
    {/if}
  </div>
                        {*mod starts*}
                            {if $s_products[$subcategory.categoryid] ne ''}
                            <ul style="float:left">
                                {foreach from=$s_products[$subcategory.categoryid]  item=sprods}
                                    <li>{$sprods.product}</li>
                                {/foreach}
                            </ul>
                            {/if}
                        {*mod ends*}


{/foreach}

<div class="clearing"></div>



skin1/customer/main/subcategories_list.tpl:
Code:

{*
$Id: subcategories_list.tpl,v 1.5 2008/11/05 14:22:39 max Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
<table cellspacing="0" summary="{$lng.txt_list_of_subcategories|escape}">

  <tr>
    <td>
      <ul class="subcategories">

        {foreach from=$subcategories item=subcat}
          <li>
            <a href="home.php?cat={$subcat.categoryid}">{$subcat.category|escape}</a>
            {if $config.Appearance.count_products eq "Y"}
              {if $subcat.product_count}
                ({$subcat.product_count} {$lng.lbl_products})
              {elseif $subcat.subcategory_count}
                ({$subcat.subcategory_count } {$lng.lbl_categories|lower})
              {/if}
            {/if}
                        {*mod starts*}
                            {if $s_products[$subcat.categoryid] ne ''}
                            <ul>
                                {foreach from=$s_products[$subcat.categoryid]  item=sprods}
                                    <li>{$sprods.product}</li>
                                {/foreach}
                            {/if}
                            </ul>
                        {*mod ends*}

          </li>
        {/foreach}
      </ul>
    </td>
  </tr>
</table>


this is a basic way to insert products. You may improve layout according to your requirements.

inboxnews 06-02-2009 07:36 AM

Re: How do I display all subcategories along with all products
 
Quote:

Originally Posted by Chrisb
This code seems to change the layout of the individual products. is there a way to keep the individual products layout but have the products under the subcategories?


Yeah, I'm looking for a way to run the subcategory links along with the existing product list in alphabetical order, instead of the stock subcategory's listing on top, followed by the product list beneath.

Stock x-cart layout, subcats (no icon/description), products include icon/description:

a subcat1
b subcat2
c subcat3
_______________

a product1
b product2
c product3


Desired Mod should include product/subcat name + description and icon and sort alphabetically:

a product1
b product2
c subcat1
d product3
e subcat2
f subcat3

effour 06-03-2009 08:06 PM

Re: How do I display all subcategories along with all products
 
This mod is excatly what i'm looking for but I want to keep my existing product.tpl format, not have it reoganized.

ANy advice?

AusNetIT 12-03-2009 03:12 PM

Re: How do I display all subcategories along with all products
 
Quote:

Originally Posted by MoonDog
RobinBraves,

Looks like you've done everything correct. All you need to do now is to convert the sample code in subcategories.tpl to something that will read your data and place it formated on the page.

If you need some code to get you going I've gathered some code from various different threads and altered the subcategories.tpl file to show the output in icons and text. It is also hyperlinked so that you can click on the icon and the text. I've attached a thumbnail so you can see what it looks like.

First, add this code to the end of your skin1.css file:
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 33%;
      PADDING-LEFT: 5px;
}

Then replace the code from <table> to </table> in the skin1/customer/main/subcategories.tpl file with the code below:
Code:


<table cellspacing="5" width="100%" border="2">
{foreach from=$subcategories item=subcat}
<tr>
<td class="ColumnTitles" valign="top"><a title="{$subcat.description}" <a href="home.php?cat={ $subcat.categoryid }"><img src="{if $subcat.icon_url}{$subcat.icon_url}{else}{$xcart_web_dir}/default_image.gif{/if}" alt="" /><br>
<font class="ItemsList">{ $subcat.category|escape }</font></a>
</td></tr>
{foreach from=$subcat.products item=subproduct}
{if $tmp is div by 3}
<tr><td colspan="3"></td></tr>
<tr valign="top">
{/if}
{ if $tmp and $first_subproduct ne "Y" }
{assign var="tmp" value=0}
{assign var="first_subproduct" value="Y"}
{/if}
{if subproduct}
<td class="ColumnTitles" valign="top"><a title="{$subproduct.description}" <a href="product.php?productid={$subproduct.productid}&amp;cat={ $subproduct.productid }&amp;cat={$cat}&amp;page={$navigation_page}"><img src="{if $subproduct.tmbn_url}{$subproduct.tmbn_url}{else}{$xcart_web_dir}/default_image.gif{/if}" alt="" /><br>
{$subproduct.product|escape}
{/if}
<br>
{assign var="tmp" value=$tmp+1}
{/foreach}
{if $tmp is not div by 3}
{assign var="tmp" value=3}
{/if}
{/foreach}
</tr>
</td>
</table>

The above code produces three columns.
If you need to change it to two column then change these 2 lines of code in subcategories.tpl:
Code:


{if $tmp is div by 3}
<tr><td colspan="3"></td></tr>

For two columns you need to replace both number 3's to 2
And for 4 columns you need to replace them to 4

And also at these 2 lines of code:
Code:

{if $tmp is not div by 3}
{assign var="tmp" value=3}
{/if}


You also need to change the percentage code you placed in your skin1/skin1.css file.

Example: for 2 columns it's 50%
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 50%;
      PADDING-LEFT: 5px;
}

Example: for 4 columns it's 25%
Code:


.ColumnTitles {
      TEXT-ALIGN: center;
      WIDTH: 25%;
      PADDING-LEFT: 5px;
}


Unfortunately I've been so busy, I didn't have much time to test it out completely, but it's a start to get you going. You might have to change the table code or the css code to what you need. I also didn't work on the sort order (it's ordered alphabetically), it's different than the sort order on the menu (see the thumbnail). You can change the position order in the categories section of the admin side.
Anyway, hope this will get you going.

- MoonDog -



is this going to work in 4.2?

Thanks


All times are GMT -8. The time now is 11:18 AM.

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