Magento – Get attribute_code or attribute_id in layered catalog\layer\view.phtml

layered-navigation

I used a Layered Navigation SEO to make my layered navigation to have a multiselect on filter and AJAX updater result and layered navigation. Every filter in layered navigation is in Bootstrap 3 collapse. The problem is that when user extend a filter and select something, layered navigation is reloaded by AJAX request and every field is collapsed, witch is annoying.

I want to make some customization on that and add to each filter some unique HTML attribute like data-attribute-code and add some info about witch collapse are extend, so I can set then to be extended when layered navigation is reloaded.
Current problem that i have is that i can get only the name of the filter with $_filter->getName() witch is not good to use like identification for filter. But when i try to get a attribute code or id i get empty stings. I try with this code

$_filter->getId();
$_filter->getCode();
$_filter->getAttributeId();
$_filter->getAttributeCode();

If someone can help me and show how to get attribute ID or Code i will be very thankful.

Best Answer

This will give the attribute code:

$_filter->getRequestVar();

You can get attribute id by using the following:

// $attributeCode = YOUR_ATTRIBUTE_CODE; 
// In your case it will be as below:
$attributeCode = $_filter->getRequestVar();

$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
                ->setCodeFilter($attributeCode)
                ->getFirstItem();

$attributeId = $attributeInfo->getAttributeId();
Related Topic