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

Subcategory Mods on 4.2.0

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 01-27-2009, 02:35 PM
 
artmatt artmatt is offline
 

Member
  
Join Date: Aug 2006
Posts: 12
 

Default Subcategory Mods on 4.2.0

I've been struggling to find much info on here for modifying the categories menu to display subcategories on xcart 4.2.0.

I had 3 different requests.

The first was probably the most common, which was that the client wanted the subcategories to appear as you clicked each category and to remain whilst they looked at products.

The Second was to display the categories and subcategories all the time

The Thirs was to display the categories and subcategories all the time but not be able to click on the categories (in effect they are just headings)

To do this I used some code from on here for older versions and made some code up.

For any of these you first need to let the pages have access to the subcategories. This is done by editing the file "include/categories.php" look for the following line:

Code:
if (!empty($subcategories)) {

and just before it add the following block of code:

Code:
function func_getallsubcat(){ $a =func_get_categories_list("", true, "all"); $b=$a['all_categories']; $c=array(); foreach ($b as $k=>$v){ if($v['parentid']!="0") $c[$v['parentid']][]=$v; } return $c; } $smarty->assign("allsubcategories", func_getallsubcat());


Once that has been added you just need to alter the customer/categories.tpl template file to tell it to use the new variable.

For the first method I wrote the following code:

Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {if $c.categoryid eq $par} {foreach from=$allsubcategories.$par item=sub} {if $sub.parentid eq $c.categoryid} <a href="home.php?cat={$sub.categoryid}" class="subMenuItem">{$sub.category}</a> {/if} {/foreach} {/if} {foreach from=$allcategories item=cat} {if $cat.parentid eq $c.categoryid} <a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}


For the second method I instead used the following code:

Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {assign var=in value=$c.categoryid} {foreach from=$allsubcategories.$in item=cat} {if $cat.parentid eq $c.categoryid} <a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}


And the third method was very similar to the second method and used the following code:

Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li>{$c.category}</li> {assign var=in value=$c.categoryid} {foreach from=$allsubcategories.$in item=cat} {if $cat.parentid eq $c.categoryid} <a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}



Hopefully that will help someone else on version 4.2. I've not extensively tested it yet but it seemed to work fine. I only needed to use it with one level of subcategories so I've no idea if it will work with multiple levels. - I doubt it though!

I made a style up which I put at the end of the main.css file - you can make your own up but here is mine:

Code:
a.subMenuItem{ display:block; margin-left:23px; text-decoration:none; } a.subMenuItem:hover{ text-decoration:underline; }


*update* I just tried adding a third level category ( a sub-subcategory ) and as I expected it won't show on the menu but will operate fine but the third level will show in the middle like the basic x-cart way does.
__________________
Xcart Pro Version 4.1.2
Reply With Quote

The following 4 users thank artmatt for this useful post:
joannet (10-12-2009), NakedSticker (10-13-2009), Regs (06-19-2009), user1 (03-29-2009)
  #2  
Old 03-05-2009, 08:57 AM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default Re: Subcategory Mods on 4.2.0

thank you sir - excellent
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #3  
Old 03-07-2009, 12:31 PM
  bullfrog's Avatar 
bullfrog bullfrog is offline
 

eXpert
  
Join Date: Oct 2004
Location: Oregon, USA
Posts: 366
 

Default Re: Subcategory Mods on 4.2.0

I decided try 4.2 for my newest store, drop ship only, with about 2600 products in many subcategories, but only 2 main categories.

The difference I see in the default menu system for 4.2 was not expected, as I've been using a modified menu and forgot what the original was like. The default menu 4.2 menu system will not work well with my new store.

I'm not as talented as artmat in coding, so I was considering going back to 4.1.x for the new store. Now I'll experiment with his code and see what it does for 4.2.

I might consider Fancy Categories, but my prior experience with that is that is it not suitable for large stores due to speed issues. I previously tried it with 4.0.x stores, and gave up. Can anyone verify if Fancy Cats still has speed issues when dealing with large stores, and with 4.2 in particular?

Also, I see new FREE skins are now posted for 4.2. See them at http://xcart-demo.qualiteam.biz/demo/home.php

I appreciate the work you've done. Thanks for sharing!
__________________
Bullfrog ~~~ X-Cart Gold v4.7.2 (2) v4.7.8. ⌠If the road is easy, you're likely going the wrong way.■ ― Terry Goodkind
Reply With Quote
  #4  
Old 03-08-2009, 10:43 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default Re: Subcategory Mods on 4.2.0

ok question:

1) Dont you still want to show the subcategories in <li> form?
2) How can I do this and be able to have the subcategories basically indented from the main categories in <li> form?

I would appreciate any help on this.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #5  
Old 03-09-2009, 06:56 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

I suppose HTML produced by the this variant of subcategories.tpl wouldn't pass validation
Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {if $c.categoryid eq $par} {foreach from=$allsubcategories.$par item=sub} {if $sub.parentid eq $c.categoryid} <a href="home.php?cat={$sub.categoryid}" class="subMenuItem">{$sub.category}</a> {/if} {/foreach} {/if} {foreach from=$allcategories item=cat} {if $cat.parentid eq $c.categoryid} <a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}

It's better try like this
Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {if $c.categoryid eq $par} {foreach from=$allsubcategories.$par item=sub} {if $sub.parentid eq $c.categoryid} <li class="subcat"><a href="home.php?cat={$sub.categoryid}" class="subMenuItem">{$sub.category}</a></li> {/if} {/foreach} {/if} {foreach from=$allcategories item=cat} {if $cat.parentid eq $c.categoryid} <li class="subcat"><a href="home.php?cat={$cat.categoryid}" class="subMenuItem">{$cat.category}</a></li> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}
and add extra css in main.css
Code:
.menu-categories-list ul li.subcat{ /*Your extra styles for nested categories here*/ }
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote

The following 3 users thank Victor D for this useful post:
NakedSticker (10-13-2009), Regs (06-19-2009), user1 (03-29-2009)
  #6  
Old 03-09-2009, 10:16 AM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default Re: Subcategory Mods on 4.2.0

VICTOR - You da man... Thanks a million.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #7  
Old 03-09-2009, 12:31 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default Re: Subcategory Mods on 4.2.0

Victor - I'm sorry... Is there anyway of showing me what to use for his second model? Please.. I would really appreciate it.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #8  
Old 03-10-2009, 02:47 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

just the same (wrap links with li elements of the specific class and define this elements style in css):
Code:
{capture name=menu} {if $active_modules.Fancy_Categories} {include file="modules/Fancy_Categories/categories.tpl"} {assign var="additional_class" value="menu-fancy-categories-list"} {else} {assign var=thiscat value=$cat} {assign var=par value=0} {foreach from=$categories item=cats} {assign var=Mcatid value=$cats.categoryid} {foreach from=$allsubcategories.$Mcatid item=subb} {if $subb.categoryid eq $thiscat} {assign var=par value=$subb.parentid} {/if} {/foreach} {/foreach} <ul> {foreach from=$categories_menu_list item=c} <li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}">{$c.category}</a></li> {assign var=in value=$c.categoryid} {foreach from=$allsubcategories.$in item=cat} {if $cat.parentid eq $c.categoryid} <li class="subcat"><a href="home.php?cat={$cat.categoryid}">{$cat.category}</a></li> {/if} {/foreach} {/foreach} </ul> {assign var="additional_class" value="menu-categories-list"} {/if} {/capture} {include file="customer/menu_dialog.tpl" title=$lng.lbl_categories content=$smarty.capture.menu}
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
  #9  
Old 03-24-2009, 09:23 AM
 
Tim CDN Tim CDN is offline
 

Advanced Member
  
Join Date: Mar 2009
Posts: 48
 

Default Re: Subcategory Mods on 4.2.0

Thanks for the great work.
I tried to implement the changes but it won't show the sub-categories.

I am not a strong programmer so pls forgive my ignorance.

Do I need to put both

a.subMenuItem{
display:block;
margin-left:23px;
text-decoration:none;
}
a.subMenuItem:hover{
text-decoration:underline;
}

and

.menu-categories-list ul li.subcat{
/*Your extra styles for nested categories here*/
}

In main.css, and if I do, what should be in place of

/*Your extra styles for nested categories here*/

Are there any other settings that might prevent the subs showing up?

Thanks
__________________
Gold 4.2.0
CDSEOPRO v.1.3.1
Advanced MiniCart
ezUpsell
One Page Checkout
Drug Test Kits
Reply With Quote
  #10  
Old 03-25-2009, 12:22 AM
  Victor D's Avatar 
Victor D Victor D is offline
 

X-Adept
  
Join Date: Aug 2008
Posts: 643
 

Default Re: Subcategory Mods on 4.2.0

Did you modify include/categories.php according to the very first post in this thread?
I slightly improved the output of this mod, but the main work is described here http://forum.x-cart.com/showpost.php?p=244930&postcount=1
Please read it carefully

If you choose my variant of template you can either use following lines or omit them if you don't want you subcats have a custom lookout.

.menu-categories-list ul li.subcat{
/*Your extra styles for nested categories here*/
}

F.e. if you want your subcat links to be red you should use
.menu-categories-list ul li.subcat{
color:#ff0000;
}
__________________
Regards,
Victor Dubiniuk

X-Cart Skins Store
- twenty two different skins for 4.1.x and 4.2.x;
- 4.3.x compatible versions are available;
- refresh you store now!

Smart menu X-Cart add-on for 4.1.8 - 4.3.x
Featured Products Slide Show X-Cart add-on for 4.1.8 - 4.3.x
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 11:59 AM.

   

 
X-Cart forums © 2001-2020