Friday, January 27, 2012

Getting a Price Filter of category or Category Filters in magento programmatically

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 .= '
<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) {

$layer = Mage::getModel('catalog/layer');
$category = Mage::getModel('catalog/category')->load($maincategoryId);
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$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()


return $html;

No comments:

Post a Comment