X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Subcategory Mods on 4.2.0 (https://forum.x-cart.com/showthread.php?t=45126)

artmatt 01-27-2009 02:35 PM

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.

mrerotic 03-05-2009 08:57 AM

Re: Subcategory Mods on 4.2.0
 
thank you sir - excellent :)

bullfrog 03-07-2009 12:31 PM

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!

mrerotic 03-08-2009 10:43 PM

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.

Victor D 03-09-2009 06:56 AM

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*/
}


mrerotic 03-09-2009 10:16 AM

Re: Subcategory Mods on 4.2.0
 
VICTOR - You da man... Thanks a million.

mrerotic 03-09-2009 12:31 PM

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.

Victor D 03-10-2009 02:47 AM

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}


Tim CDN 03-24-2009 09:23 AM

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

Victor D 03-25-2009 12:22 AM

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


All times are GMT -8. The time now is 07:52 AM.

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