$categoryid = 43;
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($categoryid);
$layer->setCurrentCategory($category);
$attributes = $layer
->getFilterableAttributes()
->addDisplayInAdvancedSearchFilter()
;
Mage::log($attributes->getSelect());
foreach ($attributes as $attribute) {
echo $attribute->getAttributeCode(). " ". $attribute->getStoreLabel() ."<br/>";
}
I want tho filters attributes which is used in layered navigation and used in advance search. When I print query the result query working fine but print the attribute filter they give only getFilterableAttributes
.
The getFilterableAttributes
method class Mage_Catalog_Model_Layer
load collection first then I use addDisplayInAdvancedSearchFilter
cause will effect after load collection.
I want to know is there any method load collection after loading the method. Any one face these kind of problem then please help how it works.
In class Mage_Catalog_Model_Layer
method getFilterableAttributes
have following code.
public function getFilterableAttributes()
{
$setIds = $this->_getSetIds();
if (!$setIds) {
return array();
}
/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();
return $collection;
}
When I add $collection->addDisplayInAdvancedSearchFilter()
before $collection->load()
but its wokring fine. Like This.
public function getFilterableAttributes()
{
$setIds = $this->_getSetIds();
if (!$setIds) {
return array();
}
/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection = $this->addDisplayInAdvancedSearchFilter();
$collection->load();
return $collection;
}
Its work fine.
I don't want to rewrite Mage_Catalog_Model_Layer
Model.
Thanks
Best Answer
After Load collection doesnt make new database request. You can use
$collection->clear();
.And add filters to returned collection.