If you need to call or display category filters by using category id in magneto use this code
this below code will display price Filter of category
$html='<div>';
$html .= '
<h4>Price</h4>
<ul class="price_grid">';
$html .= $this->priceHtmlnav($maincategoryId);
$html .='</ul>';
echo $html;
/*price block html
it took price filter and display in menu*/
public function priceHtmlnav($maincategoryId) {
$html='';
$layer = Mage::getModel('catalog/layer');
$category = Mage::getModel('catalog/category')->load($maincategoryId);
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
$attributes = $layer->getFilterableAttributes('price');
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
$result = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$t=str_replace('<span class="price">', "", $option->getLabel());
$t=str_replace('</span>', "", $t);
$html .='<li><a href="'.$category->getUrl().'?price='.$option->getValue()
.'">'.$t.'</a></li>';
}
}
}
return $html;
}
No comments:
Post a Comment