0

How to get filterable attributes and options in Magento for catalog search page programmatically in Magento 1?

$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($category_id);
$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 = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $count = count($result->getItems());
    if($count > 0){
        $attribute->getFrontendLabel();
        $attribute->getAttributeCode();
    }
    if($count > 0){
        foreach($result->getItems() as $option) {
            $option->getLabel();
            $option->getValue();
        }
    }
}

Above code working for Magento 1 category?

How can I do the same for catalog search?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.