📜 ⬆️ ⬇️

category tree in its own way (webasyst shop-script)

Helped someone on the forum and decided to perpetuate here.
Several options for displaying the category tree in your store or editing the category_tree.html file

1. The category tree is always open.


Remove everything from the category_tree.html file and write there
{newtree}
Then in the folder / kernel / includes / smarty / plugins create a file function.newtree.php , in which we write:
<?php
function smarty_function_newtree($params, &$smarty){

$disp='';
$disp.='<ul>';
$sql='SELECT categoryID, slug, parent, '.LanguagesManager::sql_prepareField('name').' AS name from '.CATEGORIES_TABLE. ' where parent=1 order by name';
if($r=mysql_query($sql))
while($res=mysql_fetch_assoc($r)){
$disp.='<li class="parent';
if($_REQUEST['categoryID'] == $res['categoryID']) $disp.='_current';
$disp.='"><span class="bullet">&nbsp;</span><a href="?categoryID='.$res['categoryID'].'">'.$res['name'].'</a></li>';
$disp.=subcat($res['categoryID']);
}

$disp.='</ul>';
return $disp;
}

function subcat($parid){
$disp='';
$sql='SELECT categoryID, slug, parent, '.LanguagesManager::sql_prepareField('name').' AS name from '.CATEGORIES_TABLE. ' where parent='.$parid.' order by name';
if($r=mysql_query($sql))
while($res=mysql_fetch_assoc($r)){
$disp.='<li class="child';
if($_REQUEST['categoryID'] == $res['categoryID']) $disp.='_current';
$disp.='"><span class="bullet">&nbsp;</span><span class="tab">&nbsp;</span><a href="?categoryID='.$res['categoryID'].'">'.$res['name'].'</a></li>';
$disp.=subcat($res['categoryID']);
}
return $disp;
}

?>


2. Only subcategories are visible.


On the main page, parent categories are visible, inside the category only subcategories are visible. To do this, we replace the entire contents of the category_tree.html file with the following code:
{* category navigation tree *}
<ul>
{if $categoryID eq 0}
{section name=i loop=$categories_tree} {if $categories_tree[i].categoryID != 1}
<li class="{if $categories_tree[i].level>1}child{else}parent{/if}{if $categoryID == $categories_tree[i].categoryID}_current{/if}">
{section name=j loop=$categories_tree max=$categories_tree[i].level-1}<span class="tab">&nbsp;</span>{/section}
{if $categories_tree[i].slug}
{assign var=_category_url value="?categoryID=`$categories_tree[i].categoryID`&category_slug=`$categories_tree[i].slug`"|set_query_html}
{else}
{assign var=_category_url value="?categoryID=`$categories_tree[i].categoryID`"|set_query_html}
{/if}

<span class="bullet">&nbsp;</span><a href='{$_category_url}'>{$categories_tree[i].name|escape:'html'}</a>
</li>
{/if} {/section}
{else}
{section name=i loop=$categories_tree} {if $categories_tree[i].categoryID != 1 && $categories_tree[i].parent eq $categoryID}
<li class="{if $categories_tree[i].level>1}child{else}parent{/if}{if $categoryID == $categories_tree[i].categoryID}_current{/if}">
{section name=j loop=$categories_tree max=$categories_tree[i].level-1}<span class="tab">&nbsp;</span>{/section}
{if $categories_tree[i].slug}
{assign var=_category_url value="?categoryID=`$categories_tree[i].categoryID`&category_slug=`$categories_tree[i].slug`"|set_query_html}
{else}
{assign var=_category_url value="?categoryID=`$categories_tree[i].categoryID`"|set_query_html}
{/if}

<span class="bullet">&nbsp;</span><a href='{$_category_url}'>{$categories_tree[i].name|escape:'html'}</a>
</li>
{/if} {/section}
{/if}
</ul>

UPD: CNC fixes:

Replace
$disp.='"><span class="bullet">&nbsp;</span><span class="tab">&nbsp;</span><a href="?categoryID='.$res['categoryID'].'">'.$res['name'].'</a></li>';

on
if($res['slug']!='')
$disp.='"><span class="bullet">&nbsp;</span><span class="tab">&nbsp;</span><a href="/category/'.$res['slug'].'/">'.$res['name'].'</a></li>';
else
$disp.='"><span class="bullet">&nbsp;</span><span class="tab">&nbsp;</span><a href="?categoryID='.$res['categoryID'].'">'.$res['name'].'</a></li>';

Original article

')

Source: https://habr.com/ru/post/69643/


All Articles