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

Customize Layered Navigation for differnt categories – Where to get Current Parent Category Id? 
 
burt
Member
 
Total Posts:  31
Joined:  2008-08-26
 

Hi there,

I’m trying to have different layered navigation options depending on the current category. I’m almost there now by having some if-elseif-stuff in layer/view.phtml. But right now it only works for main-categories. As soon as I go into a subcategory it doesn’t work any longer because I’m asking for the ID for the currentCategory.

So can anybody help me to get the ID for the main-store-category because getStoreCategories(); doesn’t seem to work in this phtml-file.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

This should help:

http://www.magentocommerce.com/boards/viewthread/16357/

 
Magento Community Magento Community
Magento Community
Magento Community
 
burt
Member
 
Total Posts:  31
Joined:  2008-08-26
 

Thanks for the quick answer.
But actually I already read your post before and the problem is that somehow you can’t use the getStoreCategories-function in the view.phtml for layered navigation. I always get an error.
Is there a possibility to use a handler (?) somehow – I’m not really into this kind of stuff.
Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

What is the error you are getting?

 
Magento Community Magento Community
Magento Community
Magento Community
 
burt
Member
 
Total Posts:  31
Joined:  2008-08-26
 

Warning: Invalid argument supplied for foreach() in /Applications/MAMP/bin/mamp/magento/app/design/frontend/default/bidos_theme/template/catalog/layer/view.phtml on line 32

line 32 is: 

foreach ( $this->getStoreCategories() as $_category {

I guess this function is not initiated for layer/view.phtml

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

Because the layered view is a “catalog/layer_view” block type, $this will refer to that object type as well. You need a way instead to access “catalog/navigation”, which will have the category information. Typically you do this by using a helper that has access to catalog/navigation properties. Unfortunately, that I can tell in my version, no such helper has been written for this particular object. Instead, you will need to create a block on-the-fly that is of that type, and then you can use the properties associated with it.

<?php

    $navigation_block 
$this->getLayout()->createBlock("catalog/navigation");

    foreach ( 
$navigation_block->getStoreCategories() as $_category {
        
if ( $navigation_block->isCategoryActive$_category ) ) {
            
echo $_category->getName();
        
}
    }

?>

If you compare this to the previous post I linked to, you can see the only difference is that I use the $navigation_block reference instead of $this - to my knowledge they are exactly the same.

 
Magento Community Magento Community
Magento Community
Magento Community
 
burt
Member
 
Total Posts:  31
Joined:  2008-08-26
 

WOW,
you just saved my day. great stuff. thank you very much. it just works great.
I maybe also found a solution in a german thread:

<?php echo $this->helper('catalog/category')->getCategoryUrl(Mage::registry('current_category')); ?>

Might this be a working helper? Although I would have to rewrite to get the same output.

I also have similar problem: Inside layered navigation there is the state.phtml which puts out all filters used in that moment. I want this information to be shown in a different block (its another sidebar-navi). So I created a block as you showed to me.

$state_block $this->getLayout()->createBlock("catalog/layer_view");
echo 
$state_block->getStateHtml();

… and – surprise – it really works. But only if I exclude the original layer_view block from the catalog.xml

<block type="catalog/layer_view" name="catalog.leftnav" after="-" template="catalog/layer/view.phtml"/>

Because if not, I get an error-message again:
You cannot define a correlation name ‘attr_index_65’ more than once

Also some clues on this issue? Thank you so much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
burt
Member
 
Total Posts:  31
Joined:  2008-08-26
 

Nevermind,
using the following block it now works:

$state_block $this->getLayout()->createBlock("catalog/layer_state");

Thanks again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wibbel
Member
 
Total Posts:  63
Joined:  2009-06-17
 

Hi,

I’m trying to do this very thing (I think !!), but just having no success at all so wondering if anything has changed since this post was published?

I’m using Rico Neitzel’s VertNav code too in case that affects anything, but I also disabled it and tried just using the default theme, but still with no success.

I’d like to find the ‘current category’ from within catalog/layer/view.phtml

My objective is to tweak the filters that are displayed based on the current active category name, so for example if its a particular category, don’t display a specific filter.

When I try the code suggested above, all my filters just don’t display ! I’m very new to this and so probably doing something very stupid so any help gratefully appreciated,

I’m trying to insert this code in the catalog/layer/view.phtml script with the expectation that it will display my current category name !!

<?php

    $navigation_block 
= $this->getLayout()->createBlock("catalog/navigation");

    foreach ( $navigation_block->getStoreCategories() as $_category ) {
        if 
( $navigation_block->isCategoryActive( $_category ) ) {
            echo $_category
->getName();
        }
    }
?>

Andrew

 
Magento Community Magento Community
Magento Community
Magento Community
 
citiusrab
Jr. Member
 
Total Posts:  8
Joined:  2010-08-15
 

$state_block $this->getLayout()->createBlock("catalog/layer_view");
echo 
$state_block->getStateHtml();
Hmmmm. Realy nice and easy… but I get null string by this method. What can I do wrong?
This sting <block type="catalog/layer_view" before="-" template="catalog/layer/view.phtml"/> removed from catalog.xml
and i added to the beginning of this file: document catalog/category/navigation/left.phtml, this code:

$state_block $this->getLayout()->createBlock("catalog/layer_view");
echo 
$state_block->getStateHtml();

Why, $state_block->getStateHtml() returned string(0) “”

 
Magento Community Magento Community
Magento Community
Magento Community
 
citiusrab
Jr. Member
 
Total Posts:  8
Joined:  2010-08-15
 

I’m Sorry, all works! I just not choosed any filter.

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