Skip to content

Instantly share code, notes, and snippets.

@St0iK
Created December 6, 2016 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save St0iK/12815225909cfe367efab9dec5b877e6 to your computer and use it in GitHub Desktop.
Save St0iK/12815225909cfe367efab9dec5b877e6 to your computer and use it in GitHub Desktop.
$store = Mage::app()->getStore();
$rootId = Mage::app()->getStore($store->getId())->getRootCategoryId();
// $cat = Mage::getModel('catalog/category')->load(814);
try{
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load(1183); // 3rd Category
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute) {
echo $attribute->getAttributeCode(); echo "<br>";
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();
foreach($result->getItems() as $option) {
$count[] = array('attribute_name' => $option->getLabel(),'attribute_value' => $option->getValue());
}
if($count!=null){
$json[] = array(
'code'=>$attribute->getAttributeCode(),
'name'=>ucfirst($attribute->getName()),
'count'=>$count
);
}
unset($count);
}
}
catch (Exception $e) {
$json = array('status' => false, 'message' => $e->getMessage());
}
$html = NULL;
foreach ($json as $layeredNav) {
$html = "<li><a href='#'>" . $layeredNav['name'] . "</a></li>";
$html .= "<ul>";
foreach ($layeredNav['count'] as $key => $value) {
$html .= "<li><a href='/?price=".$value['attribute_value']."'>" . $value['attribute_name'] . "</a></li>";
}
}
echo "<pre>";
print_r($html);
echo "</pre>";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment