Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. $store = Mage::app()->getStore();
  2. $rootId = Mage::app()->getStore($store->getId())->getRootCategoryId();
  3.  
  4. // $cat = Mage::getModel('catalog/category')->load(814);
  5.  
  6. try{
  7. $layer = Mage::getModel("catalog/layer");
  8. $category = Mage::getModel("catalog/category")->load(1183); // 3rd Category
  9. $layer->setCurrentCategory($category);
  10. $attributes = $layer->getFilterableAttributes();
  11. foreach ($attributes as $attribute) {
  12. echo $attribute->getAttributeCode(); echo "<br>";
  13. if ($attribute->getAttributeCode() == 'price') {
  14. $filterBlockName = 'catalog/layer_filter_price';
  15. } elseif ($attribute->getBackendType() == 'decimal') {
  16. $filterBlockName = 'catalog/layer_filter_decimal';
  17. } else {
  18. $filterBlockName = 'catalog/layer_filter_attribute';
  19. }
  20. $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
  21.  
  22. foreach($result->getItems() as $option) {
  23.  
  24. $count[] = array('attribute_name' => $option->getLabel(),'attribute_value' => $option->getValue());
  25. }
  26. if($count!=null){
  27. $json[] = array(
  28. 'code'=>$attribute->getAttributeCode(),
  29. 'name'=>ucfirst($attribute->getName()),
  30. 'count'=>$count
  31. );
  32. }
  33. unset($count);
  34. }
  35. }
  36. catch (Exception $e) {
  37. $json = array('status' => false, 'message' => $e->getMessage());
  38. }
  39.  
  40. $html = NULL;
  41. foreach ($json as $layeredNav) {
  42. $html = "<li><a href='#'>" . $layeredNav['name'] . "</a></li>";
  43. $html .= "<ul>";
  44. foreach ($layeredNav['count'] as $key => $value) {
  45. $html .= "<li><a href='/?price=".$value['attribute_value']."'>" . $value['attribute_name'] . "</a></li>";
  46. }
  47. }
  48.  
  49. echo "<pre>";
  50. print_r($html);
  51. echo "</pre>";
  52. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement