PDA

View Full Version : Show full category tree


currentstyle
22-08-09, 01:00
To show the complete category listing, use this code, with a check to make sure that if there is a third level it displays and if there isn't it doesn't.


define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient();
$categorytree= array("iCategoryId" => 0, "bExpandAllBranches" => true);
$oResponse= $oClient->call('getCategoryTree', $categorytree);
echo '<ul>';
foreach($oResponse->oCategoryTree->oCategory as $details){
$id = $details->iId;
$name = $details->sName;
echo '<li><a href="'.$id.'">'.$name.'</a><ul>';
foreach($details->oCategoryTree->oCategory as $details2){
$id = $details2->iId;
$name = $details2->sName;
$arraycheck1 = $details2->oCategoryTree->oCategory;
if(!empty($arraycheck1)){

echo '<li><a href="category.php?catid='.$id.'">'.$name.'</a>';

}
else
{
echo '<li><a href="category.php?catid='.$id.'">'.$name.'</a>';
}
$arraycheck = $details2->oCategoryTree->oCategory;
if(!empty($arraycheck)){
echo '<ul>';
foreach($details2->oCategoryTree->oCategory as $details3){
$id = $details3->iId;
$name = $details3->sName;
echo '<li><a href="category.php?catid='.$id.'">'.$name.'</a></li>';
}
echo '</ul>';
}
else
{
}
}
echo '</ul>';



}
echo '</ul>';


I have no idea why the sportswear & swimwear category is such a pig, but, there we are.

authcode
22-08-09, 08:53
I've always had problems with the sportwear and swimwear category. I think swimwear is classed as adult for some reason, which seems to cause problems, but I've never been inclined to track it down.

currentstyle
22-08-09, 12:30
It appears that sportswear & swimwear has 4 empty child categories as far as my investigations go, and these are causing problems.

The only way I see around it is to check for category ID 251 and then adjust your code accordingly. Or, hardcode the category menu, and then show second and third level cats in a different menu.

GeorgeGaz
24-08-09, 10:05
Hi currentstyle,

What is happening is that Sportswear & Swinwear has four "twinned" categories as grand children.

Twinned categories was a v1 feature but something that was removed for v2.

I can delete the twins and this should then make it easier to use.

Thanks

currentstyle
24-08-09, 10:54
That would be brilliant George

GeorgeGaz
24-08-09, 11:16
Twins deleted for the Swimwear category.

We are assessing the repercussions of cleaning the whole tree later today.

Regards

Amoochi
24-08-09, 14:28
As with the other time/life saving code you've posted recently, thanks for sharing this. It will really help some people and for me, make my life so much easier. :)