Public Member Functions | |
__construct () | |
apply (Zend_Controller_Request_Abstract $request, $filterBlock) | |
Public Attributes | |
const | OPTIONS_ONLY_WITH_RESULTS = 1 |
Protected Member Functions | |
_getOptionText ($optionId) | |
_getItemsData () |
Definition at line 34 of file Attribute.php.
__construct | ( | ) |
Construct attribute filter
Reimplemented from Varien_Object.
Definition at line 42 of file Attribute.php.
00043 { 00044 parent::__construct(); 00045 $this->_requestVar = 'attribute'; 00046 }
_getItemsData | ( | ) | [protected] |
Get data array for building attribute filter items
Reimplemented from Mage_Catalog_Model_Layer_Filter_Abstract.
Definition at line 90 of file Attribute.php.
00091 { 00092 $attribute = $this->getAttributeModel(); 00093 $this->_requestVar = $attribute->getAttributeCode(); 00094 00095 $key = $this->getLayer()->getStateKey().'_'.$this->_requestVar; 00096 $data = $this->getLayer()->getAggregator()->getCacheData($key); 00097 00098 if ($data === null) { 00099 $options = $attribute->getFrontend()->getSelectOptions(); 00100 $optionsCount = Mage::getSingleton('catalogindex/attribute')->getCount( 00101 $attribute, 00102 $this->_getBaseCollectionSql() 00103 ); 00104 $data = array(); 00105 00106 foreach ($options as $option) { 00107 if (is_array($option['value'])) { 00108 continue; 00109 } 00110 if (Mage::helper('core/string')->strlen($option['value'])) { 00111 // Check filter type 00112 if ($attribute->getIsFilterable() == self::OPTIONS_ONLY_WITH_RESULTS) { 00113 if (!empty($optionsCount[$option['value']])) { 00114 $data[] = array( 00115 'label' => $option['label'], 00116 'value' => $option['value'], 00117 'count' => $optionsCount[$option['value']], 00118 ); 00119 } 00120 } 00121 else { 00122 $data[] = array( 00123 'label' => $option['label'], 00124 'value' => $option['value'], 00125 'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0, 00126 ); 00127 } 00128 } 00129 } 00130 00131 $tags = array( 00132 Mage_Eav_Model_Entity_Attribute::CACHE_TAG.':'.$attribute->getId() 00133 ); 00134 00135 $tags = $this->getLayer()->getStateTags($tags); 00136 $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags); 00137 } 00138 return $data; 00139 }
_getOptionText | ( | $ | optionId | ) | [protected] |
Get option text from frontend model by option id
int | $optionId |
Definition at line 54 of file Attribute.php.
00055 { 00056 return $this->getAttributeModel()->getFrontend()->getOption($optionId); 00057 }
apply | ( | Zend_Controller_Request_Abstract $ | request, | |
$ | filterBlock | |||
) |
Apply attribute option filter to product collection
Zend_Controller_Request_Abstract | $request | |
Varien_Object | $filterBlock |
Reimplemented from Mage_Catalog_Model_Layer_Filter_Abstract.
Definition at line 66 of file Attribute.php.
00067 { 00068 $filter = $request->getParam($this->_requestVar); 00069 if (is_array($filter)) { 00070 return $this; 00071 } 00072 $text = $this->_getOptionText($filter); 00073 if ($filter && $text) { 00074 Mage::getSingleton('catalogindex/attribute')->applyFilterToCollection( 00075 $this->getLayer()->getProductCollection(), 00076 $this->getAttributeModel(), 00077 $filter 00078 ); 00079 $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter)); 00080 $this->_items = array(); 00081 } 00082 return $this; 00083 }
const OPTIONS_ONLY_WITH_RESULTS = 1 |
Definition at line 36 of file Attribute.php.