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

Tim CDN 03-25-2009 07:45 PM

Re: Subcategory Mods on 4.2.0
 
Thanks, still working on it. Pretty confusing for a new programmer.

Victor D 03-26-2009 01:43 AM

Re: Subcategory Mods on 4.2.0
 
Three different results can be achieved by following this mod.
What model you are trying to implement?

Real working horse for this mod is the .tpl and .php files modification
CSS is required to specify additional lookout

So if you don't see subcats try to execute cleanup.php on your store or clear templates cache in admin
If it won't improve situation you should revise changes you made to php and tpl one more time

user1 03-29-2009 07:48 AM

Re: Subcategory Mods on 4.2.0
 
Hello there.

First of all I would like to thank Victor D and artmatt for their excellent work and support. I could use some help right now, since I don't have knowledge of html or css.

I want to use the first model that artmatt used in post #1. So I want my Categories panel to show a category's subcategories only when a customer clicks on that category and browses its products. :D/ (it's simple, don't you get it?)

I want to go a little bit further and move the subcategory's text and front icon a bit to the right. That way, it will be easier to distinguish the categories from subcategories. I even want to change the icon in front of subcategories.

So I used the following...


In file "include/categories.php" look for the following line: (taken from post #1)

Code:

if (!empty($subcategories)) {

and just before it add the following block of code: (taken from post #1)

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());


Open file "skin1/customer/categories.tpl"

Add {* at the start of the file and *} at the end of the file. You should have something like this:

Code:

{*blah blah
blah blah blah blah
blah
blah blah
blah  blah blah blah blah blah blah blah
blah blah
blah *}




Now, in the end of the file, after *} you must add: (taken from post #5)

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 finally, at the end of file "skin1/main.css" add this:

Code:

.menu-categories-list ul li.subcat {
  margin-left: 11px;
  background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px;
}


Now I have a problem. I have one category :

Name (Position)
Category 1 (Pos. 10)

with four subcategories:

Name (Position)
Alpha (Pos. 10)
Gamma (Pos. 20)
Delta (Pos. 30)
Omega (Pos. 40)

When I click on Category 1 the subcategories appear in correct position order:
Alpha
Gamma
Delta
Omega

When I click on any subcategory the order changes, the subcategories appear in WRONG position order (the new order is alphabetical):
Alpha
Delta
Gamma
Omega

One way of bypassing this it is to assign position to subcategories alphabetically. But I don't like this way. Any idea how to fix this?

Best regards,
Andrew

Victor D 03-30-2009 12:18 AM

Re: Subcategory Mods on 4.2.0
 
try to replace
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());


with
Code:

function func_getallsubcat(){
    $a =func_get_categories_list("", true);
    $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());


user1 03-30-2009 04:03 AM

Re: Subcategory Mods on 4.2.0
 
Quote:

Originally Posted by Victor D
try to replace
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());


with
Code:

function func_getallsubcat(){
    $a =func_get_categories_list("", true);
    $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());



Thank you for your answer. Still, I get the same result with this change.

I cleaned up the templates' cache but same result.

You can see the problem in my shop.


Best regards,
Andrew

Victor D 03-31-2009 04:07 AM

Re: Subcategory Mods on 4.2.0
 
finally find some time and get it( Sorting conditions implemented in x-cart by default is strange a bit so I have added resorting).
Code:

function func_getallsubcat(){
    $a =func_get_categories_list(null, true,"all");
    $b=$a['all_categories'];
    if (!function_exists("sort_cats")){
        function sort_cats($a, $b) {return $a["order_by"]> $b["order_by"];    }
    }
    uasort($b, "sort_cats");

    $c=array();
    foreach ($b as $k=>$v){
        if($v['parentid']!="0")
            $c[$v['parentid']][]=$v;
    }
    return $c;
}
$smarty->assign("allsubcategories", func_getallsubcat());


user1 03-31-2009 08:59 AM

Re: Subcategory Mods on 4.2.0
 
Quote:

Originally Posted by Victor D
finally find some time and get it( Sorting conditions implemented in x-cart by default is strange a bit so I have added resorting).
Code:

function func_getallsubcat(){
    $a =func_get_categories_list(null, true,"all");
    $b=$a['all_categories'];
    if (!function_exists("sort_cats")){
        function sort_cats($a, $b) {return $a["order_by"]> $b["order_by"];    }
    }
    uasort($b, "sort_cats");

    $c=array();
    foreach ($b as $k=>$v){
        if($v['parentid']!="0")
            $c[$v['parentid']][]=$v;
    }
    return $c;
}
$smarty->assign("allsubcategories", func_getallsubcat());



Excellent. Thank you very much.

To help newbies (like me) a little:

the above code goes in "include/categories.php" in the position described in post#13.

at the end of file "skin1/main.css" I added this:

Code:

.menu-categories-list ul li.subcat {
  margin-left: 11px;
  background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px;
}



"margin-left: 11px;" means that I move the subcategories beneath the category 11 pixels to the right. Change the number to move it left or right.

"background: transparent url(images/category_bullet_invert.gif) no-repeat 8px 5px;" with this line I changed the image (bold letters) in front of subcategories. To put your own image, put your image in folder "images" and change the image name above.

Thanks goes to everyone that helped.


Best regards,
Andrew

benz 04-01-2009 12:25 AM

Re: Subcategory Mods on 4.2.0
 
To fix the order issue, can you not just change the line from:
PHP Code:

func_get_categories_list("",true,"all"); 

to
PHP Code:

func_get_categories_list("",true,"sub_orderby"); 


Or does this no longer work in 4.2

Victor D 04-01-2009 01:20 AM

Re: Subcategory Mods on 4.2.0
 
There is no such flag in include/func/func_categories.php
I doesn't catch why sorting differs for the root and subcategory. When you browse to subcategory sorting order is changed from order_by to category_path for the same flag.

benz 04-01-2009 02:58 PM

Re: Subcategory Mods on 4.2.0
 
Apologies all, I'd forgotten that I added that flag myself ages ago.

In categories.php around line 68 you can make the following change.
(WARNING - only tested in Xcart 4.1.11)

PHP Code:

if ($current_area == "C" || $current_area == "B") {
        global 
$user_account;
        
$search_condition[] = "$sql_tbl[categories].avail='Y'";
        
$search_condition[] = "($sql_tbl[category_memberships].membershipid IS NULL OR $sql_tbl[category_memberships].membershipid = '$user_account[membershipid]')";
        if (
$flag == "all")
            
$sort_condition " ORDER BY category";
#Add this line
        
elseif ($flag == "sub_orderby")
            
$sort_condition " ORDER BY $sql_tbl[categories].order_by";
#end modification
        
else
$sort_condition " ORDER BY $sql_tbl[categories].order_by, category"


In Xcart4.1.11 you can also pass any non-null $flag string to this function call and it will do the same thing without this mod thanks to the last else clause,
eg if you call
$raj =func_get_categories_list("", true,"lorumipsum");
it still works thanks to the last else clause - the bug in the original is that it doesn't work if you leave out the flag parameter.

artmatt 05-06-2009 06:40 AM

Re: Subcategory Mods on 4.2.0
 
Not far off for 4.2.0. I've just come to need this mod again, and I needed the sorting to work so took a look into it.

As benz says in the first bit of code I posted change
Code:

$a =func_get_categories_list("", true, "all");

to
Code:

$a =func_get_categories_list("", true, "sub_orderby");

Then you need to add the bit from benz's last post but it's not on line 68 of categories.php anymore it's now on line 533ish of /include/func/func.category.php

Add the two lines of code and it seems to work perfectly.

Hope this helps someone

buckyreal2 06-11-2009 03:35 PM

Re: Subcategory Mods on 4.2.0
 
Anybody know how to make this work with sub- subcategories?

artmatt 06-11-2009 11:15 PM

Re: Subcategory Mods on 4.2.0
 
I've made it work with sub-sub cats, will post how it's done when I get time.

But if I remember correctly all the data is there, so you just have to add the code to the categories.tpl file to display the sub-sub-cats.

Have a play you just need to make a sub loop in the same format, it can then be extended again and again for each further level you require.

Hope that makes sense

Sorry I haven't got time to post it at the moment

wmreich 06-14-2009 07:01 PM

Re: Subcategory Mods on 4.2.0
 
Thank you artmatt :)

buckyreal 06-18-2009 11:00 AM

Re: Subcategory Mods on 4.2.0
 
Thank you artmatt! The code you posted worked great!

I hope you can find time to post the sub-sub category sub-loop. I understand what you are saying, but I don't know where to start to implement it.

mrerotic 06-22-2009 10:33 AM

Re: Subcategory Mods on 4.2.0
 
How can you make this only show subcategories in a certain category? Victor if you can help I would really appreciate this.

Also, can you limit the amount of results shows for subcategories and maybe leave it with another one called 'More...'?

mrerotic 07-02-2009 09:23 PM

Re: Subcategory Mods on 4.2.0
 
Bump any ideas how to show like 5 random subcategories in a main category? Any help would be greatly appreciated.

Victor D 07-13-2009 01:14 AM

Re: Subcategory Mods on 4.2.0
 
Quote:

5 random subcategories in a main category?
These categories should be from the root level or from any level?

pairodimes 07-13-2009 09:23 AM

Re: Subcategory Mods on 4.2.0
 
Quote:

Originally Posted by artmatt
Not far off for 4.2.0. I've just come to need this mod again, and I needed the sorting to work so took a look into it.

As benz says in the first bit of code I posted change
Code:

$a =func_get_categories_list("", true, "all");

to
Code:

$a =func_get_categories_list("", true, "sub_orderby");

Then you need to add the bit from benz's last post but it's not on line 68 of categories.php anymore it's now on line 533ish of /include/func/func.category.php

Add the two lines of code and it seems to work perfectly.

Hope this helps someone


I tried this method - found the line in the /include/func/func.category.php - patched it - but the categories still show up in the wrong order once we get to the Sub category level. Its weird how it shows up in the correct order when we are on the Parent Category (which dsiplays the subcategory list). Any corrolation?

Also - another question - is it possible to Not Show the <UL> for Categories that do NOT HAVE Sub categories.

The way the code is written - It runs a loop on all Categories - then runs an IF - the Category has a parent ID of the same number - then display the Sub Category list.

But I wish I could run a loop that only displayed Categories that had a ParentID of '0' (root) then ran an IF - the Category has a parent ID of the same number - then display the Sub Category list.

The reason is - this is creating unncessary UL tags and shifting my css design. Anybody know how to do this?

Is there any way to run an IF statement on the $allcategories array to check if it returns Nothing (null - no value)? Then print the UL only if the value was NOT Null?

iDC Photography 08-18-2009 04:01 PM

Re: Subcategory Mods on 4.2.0
 
This mod is freakin awesome!

I needed something to get me half way to making an accordion menu, and this did the job.

I have followed all the directions I could, but am having a strange problem.

Menu works GREAT on the homepage, no problems at all.

But every other page doesn't load the subcategories. I tried with the original code and my "tweaked" version to display as an accordion.

Why would the subcats not display on the child pages? Any ideas?

The shop isn't open for business yet, and I am in the styling stages.

If you need to see it, send me a PM.

THX!

iDC Photography 08-18-2009 09:18 PM

Re: Subcategory Mods on 4.2.0
 
Haha. My bad. I put the catagories.php code AFTER the line instead of BEFORE it. Such a newbie.....

Got the accordion working like a charm. Thanks Victor for you ingenuity!

iDC Photography 08-19-2009 06:43 AM

Re: Subcategory Mods on 4.2.0
 
One more question...

I don't want you to do all the work, but could someone point me in the right direction?

I need to make an "active" class for the nested elements so that i can customize the javascript to leave the category section in the menu open if an item from that category is being viewed. I would also like the have the subcategory highlighted, but that isn't as crucial. (Using an accordion style menu)

I am going to start tinkering with it today, but any ideas would be awesome!

Thanks!

jonah

iDC Photography 08-20-2009 06:36 AM

Re: Subcategory Mods on 4.2.0
 
I got it. Not only that but I was able to also insert a class for the active subcategory so both the active category and the active subcategory are given custom classes to as to help the customer keep track of where the are in the menu.

Thanks to all who started this thread. It has helped infinitely!

xcel 09-11-2009 12:26 PM

Re: Subcategory Mods on 4.2.0
 
Quote:

Originally Posted by artmatt
I've made it work with sub-sub cats, will post how it's done when I get time.

But if I remember correctly all the data is there, so you just have to add the code to the categories.tpl file to display the sub-sub-cats.

Have a play you just need to make a sub loop in the same format, it can then be extended again and again for each further level you require.

Hope that makes sense

Sorry I haven't got time to post it at the moment


artmatt... any possibility of posting your fix for sub-sub cats?

Also... could you possibly explain how I could get it to work with sub-sub-sub cats??? like this...

MAIN
SUB 1
SUB 2
SUB 3

Thanks in advance (and thanks to user1 for cleaning things up a bit)

mescalito_ve 11-04-2009 02:52 AM

Re: Subcategory Mods on 4.2.0
 
Hello thanks for this mod is very ussefull.

I im using it but when you click in a subcategory the subcategory sub menu dissapears, im i missing something or it works like that?

artmatt 02-11-2010 04:29 AM

Re: Subcategory Mods on 4.2.0
 
As a quick update I can confirm this also works with the new 4.3.0 version of x-cart. The new version does include a few extra choices with the Fancy Categories module being included, but it still doesn't do a "normal" functional menu. I've just followed my own post from the first page and it works fine, all sorting on sub-menus is correct as well

*EDIT*

Sorting wasn't correct! It just happened to be correct because it was in alphabetic order anyway!

Code should be as per Victors Code on post 16:

http://forum.x-cart.com/showpost.php?p=253759&postcount=16

kooki 03-03-2010 08:22 AM

Re: Subcategory Mods on 4.2.0
 
This code works great, but like others I really need to know how to get sub-sub categories appearing..

Penelope 05-05-2010 08:29 AM

Re: Subcategory Mods on 4.2.0
 
Thanks to everyone for the fantastic information in this thread. I thought modifying the categories menu to include subcats would be a real trial-and-error effort. But all of your input has made it painless!

gatordp 08-07-2010 08:10 PM

Re: Subcategory Mods on 4.2.0
 
I tried doing this mod on 4.2.2 and it all seemed to work OK, but I have a custom skin and when I used this it added bullets in front of the Main Categories and changed the font size.

I'm sure this is a css issue. Anyone know where I might look to fix this and keep the same formatting I had?

Jeremy Smith 09-22-2010 04:08 AM

Re: Subcategory Mods on 4.2.0
 
Would this work with v4.1.11?

Also would this allow when viewing the front page, to display the root categories as defined in the side bar, then when the user selects a value say:

root_category1, it then shows all the sub categories applied to that root category.

But still keeping the value of the root_category1.

Then when the user selects say:

sub_category1 it keeps both displayed in the html drop down select box.

Would this accomplish that requirement?

Sorry if this has already been asked etc but just wanted to clarify that.

Thanks,
Jeremy


All times are GMT -8. The time now is 09:20 AM.

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