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)
-   -   Showing all categories, subcategories and sub-subcategories (https://forum.x-cart.com/showthread.php?t=72442)

McGuireArmyNavy 07-15-2015 07:07 AM

Showing all categories, subcategories and sub-subcategories
 
I had my home page redone to put the categories on top instead of on the side. Using code from stackoverflow.com I was able to show subcategories together with parent categories. I need to go down a level or two, and can't seem to figure it out. Any ideas?

The code I used is below:
in include/common.php, I added the following under "Get categories menu data
Code:

+
+            if (!isset($cat) || 0 == intval($cat)) {
+                $extended_categories = func_get_categories_list(0, true, true, 1);
+
+                if (!empty($extended_categories)) {
+                    $smarty->assign('extended_categories_list', $extended_categories);
+                }
+            }

and in /common_files/customer/categories.tpl, I added
Code:

<ul>
{foreach from=$categories_menu_list item=c}
<li><a href="home.php?cat={$c.categoryid}" title="{$c.category|escape}"><strong>{$c.category}</strong></a>

    <!-- list subcategories here-->
    {foreach from=$extended_categories_list item=ec}
      {if $ec.parentid eq $c.categoryid}<li><a href="home.php?cat={$ec.categoryid}" style="font-size:10px;">{$ec.category|escape}</a></li>{/if}
    {/foreach}

{/foreach}
</ul>


What do I do to go down further levels??

totaltec 07-16-2015 04:50 AM

Re: Showing all categories, subcategories and sub-subcategories
 
Looking in /include/func/func.category.php:
Code:

function func_get_categories_list($cat = 0, $short_list = TRUE, $need_sublevel = FALSE, $max_level = 0)

See that $max_level = 0 in the function arguments above? Looks to me like you are calling this function with this code:
Code:

$extended_categories = func_get_categories_list(0, true, true, 1);

So the last parameter you are feeding it is a 1, $maxlevel = 1. Try increasing it and see what you get.

PhilJ 07-16-2015 05:28 AM

Re: Showing all categories, subcategories and sub-subcategories
 
v4.x - Up to 5 levels... ensure Modules > Flyout Menus is enabled + 'Cache the menu' is disabled.

Code:

<ul>
{foreach from=$categories_menu_list item=c}
<li><a href="home.php?cat={$c.categoryid}">{$c.category}</a>
    {if $c.childs}
    {foreach from=$c.childs item=sc name=sc}
    {if $smarty.foreach.sc.first}<ul>{/if}
    <li><a href="home.php?cat={$sc.categoryid}">{$sc.category}</a>
        {if $sc.childs}
        {foreach from=$sc.childs item=ssc name=ssc}
        {if $smarty.foreach.ssc.first}<ul>{/if}   
        <li><a href="home.php?cat={$ssc.categoryid}">{$ssc.category}</a>
            {if $ssc.childs}
            {foreach from=$ssc.childs item=sssc name=sssc}
            {if $smarty.foreach.sssc.first}<ul>{/if}   
            <li><a href="home.php?cat={$sssc.categoryid}">{$sssc.category}</a>
                {if $sssc.childs}
                {foreach from=$sssc.childs item=ssssc name=ssssc}
                {if $smarty.foreach.ssssc.first}<ul>{/if}   
                <li><a href="home.php?cat={$ssssc.categoryid}">{$ssssc.category}</a></li>
                {if $smarty.foreach.ssssc.last}</ul>{/if}
                {/foreach}
                {/if}
            </li>
            {if $smarty.foreach.sssc.last}</ul>{/if}
            {/foreach}
            {/if}
        </li>
        {if $smarty.foreach.ssc.last}</ul>{/if}
        {/foreach}
        {/if}
    </li>
    {if $smarty.foreach.sc.last}</ul>{/if}
    {/foreach}
    {/if}
</li>
{/foreach}
</ul>


McGuireArmyNavy 07-16-2015 06:12 AM

Re: Showing all categories, subcategories and sub-subcategories
 
Thank you guys, I will see if we cna make this work.
PhilJ, can I do this without flyout menus? I am using customized design for my categories.

PhilJ 07-16-2015 06:28 AM

Re: Showing all categories, subcategories and sub-subcategories
 
You can, but why bother, just use the code.

McGuireArmyNavy 07-16-2015 08:06 AM

Re: Showing all categories, subcategories and sub-subcategories
 
Thank you PhilJ.
I got it working, now I just need to tweak the design to get it back to where I really need it, but all the information is now showing.

PhilJ 07-16-2015 08:18 AM

Re: Showing all categories, subcategories and sub-subcategories
 
cool.


All times are GMT -8. The time now is 05:21 AM.

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