00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Catalog_Block_Layer_View extends Mage_Core_Block_Template
00035 {
00036
00037
00038
00039
00040
00041 protected function _prepareLayout()
00042 {
00043 $stateBlock = $this->getLayout()->createBlock('catalog/layer_state')
00044 ->setLayer($this->getLayer());
00045
00046 $categryBlock = $this->getLayout()->createBlock('catalog/layer_filter_category')
00047 ->setLayer($this->getLayer())
00048 ->init();
00049
00050 $this->setChild('layer_state', $stateBlock);
00051 $this->setChild('category_filter', $categryBlock);
00052
00053 $filterableAttributes = $this->_getFilterableAttributes();
00054 foreach ($filterableAttributes as $attribute) {
00055 $filterBlockName = 'catalog/layer_filter_attribute';
00056 if ($attribute->getFrontendInput() == 'price') {
00057 $filterBlockName = 'catalog/layer_filter_price';
00058 }
00059
00060 $this->setChild($attribute->getAttributeCode().'_filter',
00061 $this->getLayout()->createBlock($filterBlockName)
00062 ->setLayer($this->getLayer())
00063 ->setAttributeModel($attribute)
00064 ->init());
00065 }
00066
00067 $this->getLayer()->apply();
00068 return parent::_prepareLayout();
00069 }
00070
00071
00072
00073
00074
00075
00076 public function getLayer()
00077 {
00078 return Mage::getSingleton('catalog/layer');
00079 }
00080
00081
00082
00083
00084
00085
00086 protected function _getFilterableAttributes()
00087 {
00088 $attributes = $this->getData('_filterable_attributes');
00089 if (is_null($attributes)) {
00090 $attributes = $this->getLayer()->getFilterableAttributes();
00091 $this->setData('_filterable_attributes', $attributes);
00092 }
00093 return $attributes;
00094 }
00095
00096
00097
00098
00099
00100
00101 public function getStateHtml()
00102 {
00103 return $this->getChildHtml('layer_state');
00104 }
00105
00106
00107
00108
00109
00110
00111 public function getFilters()
00112 {
00113 $filters = array();
00114 if ($categoryFilter = $this->_getCategoryFilter()) {
00115 $filters[] = $categoryFilter;
00116 }
00117
00118 $filterableAttributes = $this->_getFilterableAttributes();
00119 foreach ($filterableAttributes as $attribute) {
00120 $filters[] = $this->getChild($attribute->getAttributeCode().'_filter');
00121 }
00122
00123 return $filters;
00124 }
00125
00126
00127
00128
00129
00130
00131 protected function _getCategoryFilter()
00132 {
00133 return $this->getChild('category_filter');
00134 }
00135
00136
00137
00138
00139
00140
00141 public function canShowOptions()
00142 {
00143 foreach ($this->getFilters() as $filter) {
00144 if ($filter->getItemsCount()) {
00145 return true;
00146 }
00147 }
00148 return false;
00149 }
00150
00151
00152
00153
00154
00155
00156 public function canShowBlock()
00157 {
00158 return $this->canShowOptions() || count($this->getLayer()->getState()->getFilters());
00159 }
00160
00161
00162
00163
00164
00165
00166 protected function _getPriceFilter()
00167 {
00168 return $this->getChild('_price_filter');
00169 }
00170 }