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)

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 10:48 AM.

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