Magento: Get category layer filter attributes Programatically
Get Category layer filter attribute
$layer = Mage::getModel("catalog/layer");
// 32 cat id
$category = Mage::getModel("catalog/category")->load(32);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = 'catalog/layer_filter_decimal';
} else {
$filterBlockName = 'catalog/layer_filter_attribute';
}
$result = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
echo "<br/><br/>";
echo $attribute->getAttributeCode();
echo "<br/>";
foreach($result->getItems() as $option) {
echo $option->getLabel().'<br/>';
echo $option->getValue();
//exit();
}
}
$layer = Mage::getModel("catalog/layer");
// 32 cat id
$category = Mage::getModel("catalog/category")->load(32);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = 'catalog/layer_filter_decimal';
} else {
$filterBlockName = 'catalog/layer_filter_attribute';
}
$result = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
echo "<br/><br/>";
echo $attribute->getAttributeCode();
echo "<br/>";
foreach($result->getItems() as $option) {
echo $option->getLabel().'<br/>';
echo $option->getValue();
//exit();
}
}
Comments
Post a Comment