Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Layered Category Navigation shows wrong sub-categories when subcategory_listing block active
 
Designcomplex
Member
 
Avatar
Total Posts:  34
Joined:  2009-07-12
Hamburg
 

Hi there,

I got a strange problem that when I have the subcategory listing block active, the left layered navigation sidebar shows the subcategories of the last category displayed in the subcategory listing block… so it gets the wrong active category and shows the wrong subcategory as it seems.

subcategory_listing.phtml looks like this:

<div class=\"listing-type-list catalog-listing\">
    <
table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-bottom:5px;\">
    
<?php
    $_categories
=$this->getCurrentChildCategories();
    if(
count($_categories)):
    
$categorycount 0;
    
?>
<tr>
<?php
    
foreach ($_categories as $_category):
    if(
$_category->getIsActive()):
?>
<td style=\"text-align:center; padding-bottom:15px;\">
<?php 
    $cur_category
=Mage::getModel(\'catalog/category\')->load($_category->getId());
$layer Mage::getSingleton(\'catalog/layer\');
$layer->setCurrentCategory($cur_category);
$catName $this->getCurrentCategory()->getName();
if (
$categorycount == 0){
$class 
\"first\";
}
elseif ($categorycount == 3){
$class 
\"last\";
}
else{
$class 
\"\";
}
?>

<a href=\"<?php echo $_category->getURL() ?>\" title=\"<?php echo $this->htmlEscape($_category->getName()) ?>\"><img src=\"<?php echo $this->getCurrentCategory()->getImageUrl() ?>\" alt=\"<?php echo $this->htmlEscape($_category->getName()) ?>\" /></a>
<
h3 class=\"category-name\"><a href=\"<?php echo $_category->getURL() ?>\" title=\"<?php echo $this->htmlEscape($_category->getName()) ?>\"><?php echo $this->htmlEscape($_category->getName()) ?></a></h3>
</
td>
<?php
endif;
if(
$categorycount == 3){
$categorycount 
0;
echo 
\"</tr><tr>\";
}
else{
$categorycount
++;
}
endforeach;
endif;
?>    </tr>
    </
table>
</
div>

Any idea how to fix this or to get a workaround?

Magento Version 1.6.2.0.

Regards,
Thomas

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

It seems this is not working so well:

$_category->getIsActive()

Why not use

$_category Mage::registry('current_category');
 
Magento Community Magento Community
Magento Community
Magento Community
 
Designcomplex
Member
 
Avatar
Total Posts:  34
Joined:  2009-07-12
Hamburg
 

Hey,

when using that code instead the subcategory listing block gets the current category as many times as there are subcategories. But it doesn’t show the subcategories anymore.
wink

Any further ideas?

Best,
Thomas

 
Magento Community Magento Community
Magento Community
Magento Community
 
Designcomplex
Member
 
Avatar
Total Posts:  34
Joined:  2009-07-12
Hamburg
 

Weird, but this worked…

The subcategory listing block set the current category to the last subcategory which naturally is why the left navigation sidebar gets that category as current category and gets their children…

So I placed this code to get the real current category into functions:

<?php $cur_category=Mage::registry('current_category'?>
<?php $layer2
->setCurrentCategory($cur_category)?>

That worked for me for now.

Better solutions welcome…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top