Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Need help customizing category listing

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 11-16-2002, 09:51 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default Need help customizing category listing

OK... I need some help from the pros here... I am trying to do a customization for the category listing and just cant figure it out.

What I would like is when you click on a category, that you have the subcategory listing below the catagory that was clicked. I know that you can nest sections, but I can't figure out the proper way to do it. The closest that I have gotten is:

Code:
{* $Id: categories.tpl,v 1.14 2002/09/10 12:58:26 zorg Exp $ *} <TABLE border=0 cellPadding=5 cellSpacing=0 width=100%> <TR> <TD class=MenuTitleLine height=26 width=26 valign=center>[img]{$ImagesDir}/dingbats_categorie.gif[/img]</TD> <TD class=MenuTitleLine height=26 valign=center width="80%"><FONT class=TableLeftTitles>{$lng.lbl_categories}</FONT></TD> </TR> <tr><td colspan=2 class="TableLeftElements" nowrap> {if $config.General.root_categories eq "Y"} {section name=cat_num loop=$categories} <font class=CategoriesList>{ $categories[cat_num].category|escape }</font> {/section} {else} {section name=cat_num loop=$categories} <font class=CategoriesList>{ $categories[cat_num].category|escape }</font> {section name=cat_num loop=$subcategories} <font class=CategoriesList>[*]{ $subcategories[cat_num].category|escape }</font> {/section} {/section} {/if} </td></tr> </TABLE>

This is close but not right. It list the first category only once, then list the main categories again as su categories. Then when you click on a category, it DOES list the sub categories inder the category clicked, but it does not list the remaining categories.

If I change it to:
Code:
{* $Id: categories.tpl,v 1.14 2002/09/10 12:58:26 zorg Exp $ *} <TABLE border=0 cellPadding=5 cellSpacing=0 width=100%> <TR> <TD class=MenuTitleLine height=26 width=26 valign=center>[img]{$ImagesDir}/dingbats_categorie.gif[/img]</TD> <TD class=MenuTitleLine height=26 valign=center width="80%"><FONT class=TableLeftTitles>{$lng.lbl_categories}</FONT></TD> </TR> <tr><td colspan=2 class="TableLeftElements" nowrap> {if $config.General.root_categories eq "Y"} {section name=cat_num loop=$categories} <font class=CategoriesList>{ $categories[cat_num].category|escape }</font> {/section} {else} {section name=cat_num loop=$categories} <font class=CategoriesList>{ $categories[cat_num].category|escape }</font> {/section} {section name=cat_num loop=$subcategories} <font class=CategoriesList>[*]{ $subcategories[cat_num].category|escape }</font> {/section} {/if} </td></tr> </TABLE>
it will function halfway right, but it lists the sub categories under all the rest of the categories.

Am I making any sense at all?
Reply With Quote
  #2  
Old 11-16-2002, 10:51 PM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default Cascading Category/SubCategory Listings

Unfortunately, I have planned on doing this for a customer, but have not worked through it yet. But, I'll take a stab at this one...

If you are at the top level of the category tree, the subcategories are the same as the top-level categories, and that is why the first piece of code shows the main categories where you are expecting to see subs. The reason they aren't repeated is likely because you are using the same counter (cat_num) for both section loops. When it finishes the second section loop, the counter is left at the end and is falling out of the both the nested and outer loop.

In the second piece of code your two loops are exclusive of one another, meaning that the first loop completes {/section} prior to starting the second loop. At the top level, I would expect it to run the whole category listing twice?

Sorry, this has been more diagnostic of your code and not helping yet.

The first code snippet looks the closest. You need to give each counter variable a different name and add a test to see if the category is the same as the category that was selected prior to listing the subcategories. Otherwise, you will not know where to cascade the subcategory listing. I can work up an example next week if you still are stuck.

Hope this helps!
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #3  
Old 11-18-2002, 03:08 PM
 
jeffm jeffm is offline
 

Newbie
  
Join Date: Nov 2002
Location: Geogia (US)
Posts: 9
 

Default

I am trying to get this same feature. I found a site that utilizes it on a different platform. oscommerce open source storefront. The store is carnutz.cc. I am not a programmer by any means, but would love to pickup this code.

Thanks
Reply With Quote
  #4  
Old 11-18-2002, 03:56 PM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default SOLUTION - Category Listing w/nested subcategories

Much easier than I thought. TelaFirma was _really_ close, just added a simple check for match of $cat. This was made to the 3.2.1 customer/categories.tpl file... I didn't build a third option for root_categories, I just used the "N" option.

Quote:
{* $Id: categories.tpl,v 1.14 2002/09/10 12:58:26 zorg Exp $ *}
<TABLE border=0 cellPadding=5 cellSpacing=0 width=100%>
<TR>
<TD class=MenuTitleLine height=26 width=26 valign=center>[img]{$ImagesDir}/dingbats_categorie.gif[/img]</TD>
<TD class=MenuTitleLine height=26 valign=center width="80%"><FONT class=TableLeftTitles>{$lng.lbl_categories}</FONT></TD>
</TR>
<tr><td colspan=2 class="TableLeftElements" nowrap>

{if $config.General.root_categories eq "Y"}
{section name=cat_num loop=$categories}
<font class=CategoriesList>{ $categories[cat_num].category|escape }</font>

{/section}
{else}
{section name=cat_num1 loop=$categories}
{ $categories[cat_num1].category|escape }

{if $categories[cat_num1].categoryid == $cat}
{section name=cat_num2 loop=$subcategories}
<a class=CategoriesList href="home.php?cat={ $subcategories[cat_num2].categoryid }">
{ $subcategories[cat_num2].category|escape }</a>

{/section}
{/if}
{/section}
{/if}
</td></tr>
</TABLE>
[/quote]
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #5  
Old 11-18-2002, 05:49 PM
 
jeffm jeffm is offline
 

Newbie
  
Join Date: Nov 2002
Location: Geogia (US)
Posts: 9
 

Default

I am using version 2.4. Was able to get this to work, somewhat. Few issues, not sure if you guys are experiencing with a newer version.

1) Empty categories (no products) are showing up.
2) Once I click on the subcategory, they go away only displaying the top categories. Needs to show the second level sub categories.

Please let me know if you are not having these problems. If not, I will look to upgrading.

Thanks
Reply With Quote
  #6  
Old 11-18-2002, 06:52 PM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default Hmmm

Jeff,
I just checked on this and you are right, once you click on the subcategory, the category list reverts back to the top level categories only instead of staying with the subcategory listing. Not a big surprise considering it reparses the category listings using the new "cat" that you just clicked on and it doesn't have any subcategories to the sub-category you just clicked on. Let me think about that and look at the code tomorrow.

What about multi-level sub-categories? The "hack" that I sent out will only work for one level of sub-category. Do you have multiple levels of sub-categories?

On the issue of empty categories being displayed, the existing system already did that. If you want to shut off a category that doesn't have any products, you can "disable" that category in the admin interface.
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #7  
Old 11-19-2002, 09:08 AM
 
jeffm jeffm is offline
 

Newbie
  
Join Date: Nov 2002
Location: Geogia (US)
Posts: 9
 

Default

I do have multi levels of categories, but I only want to display the main category and the first sub-category on the left bar.

My store will be setup offering different categories and different items under that. For ease of naviagtion, once a customer picks the initial category, which they will most likely remain within, they can then navigate within that category very easily.

I will utilize the disable function on empty categories.

Thank you!
Reply With Quote
  #8  
Old 11-21-2002, 05:30 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

Yes, this is VERY close... I think that if we could just keep the single sub-cateogry list displayed, that would be enough to be useful...
Reply With Quote
  #9  
Old 11-21-2002, 08:47 AM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default Cascading Category Names

Sorry for the delay. Looks like I need to make a small change to categories.php. I'm booked solid today, but will get a change out tomorrow (Friday US time) to do this.
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #10  
Old 11-21-2002, 08:55 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

No rush... no rush at all....
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:08 PM.

   

 
X-Cart forums © 2001-2020