Mage_Catalog_Model_Layer_Filter_Attribute Class Reference

Inheritance diagram for Mage_Catalog_Model_Layer_Filter_Attribute:

Mage_Catalog_Model_Layer_Filter_Abstract Varien_Object

List of all members.

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 ()


Detailed Description

Definition at line 34 of file Attribute.php.


Constructor & Destructor Documentation

__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     }


Member Function Documentation

_getItemsData (  )  [protected]

Get data array for building attribute filter items

Returns:
array

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

Parameters:
int $optionId
Returns:
unknown

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

Parameters:
Zend_Controller_Request_Abstract $request
Varien_Object $filterBlock
Returns:
Mage_Catalog_Model_Layer_Filter_Attribute

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     }


Member Data Documentation

Definition at line 36 of file Attribute.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:39 2009 for Magento by  doxygen 1.5.8