Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement