Mage_Catalog_Model_Layer Class Reference

Inheritance diagram for Mage_Catalog_Model_Layer:

Varien_Object Mage_CatalogSearch_Model_Layer

List of all members.

Public Member Functions

 getAggregator ()
 getStateKey ()
 getStateTags (array $additionalTags=array())
 getProductCollection ()
 prepareProductCollection ($collection)
 apply ()
 getCurrentCategory ()
 setCurrentCategory ($category)
 getCurrentStore ()
 getFilterableAttributes ()
 getState ()

Protected Member Functions

 _prepareAttribute ($attribute)
 _prepareAttributeCollection ($collection)
 _getSetIds ()

Protected Attributes

 $_productCollections = array()
 $_stateKey = null


Detailed Description

Definition at line 35 of file Layer.php.


Member Function Documentation

_getSetIds (  )  [protected]

Get attribute sets idendifiers of current product set

Returns:
array

Definition at line 287 of file Layer.php.

00288     {
00289         $key = $this->getStateKey().'_SET_IDS';
00290         $setIds = $this->getAggregator()->getCacheData($key);
00291 
00292         if ($setIds === null) {
00293             $setIds = $this->getProductCollection()->getSetIds();
00294             $this->getAggregator()->saveCacheData($setIds, $key, $this->getStateTags());
00295         }
00296         return $setIds;
00297     }

_prepareAttribute ( attribute  )  [protected]

Prepare attribute for use in layered navigation

Parameters:
Mage_Eav_Model_Entity_Attribute $attribute
Returns:
Mage_Eav_Model_Entity_Attribute

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 247 of file Layer.php.

00248     {
00249         Mage::getResourceSingleton('catalog/product')->getAttribute($attribute);
00250         return $attribute;
00251     }

_prepareAttributeCollection ( collection  )  [protected]

Add filters to attribute collection

Parameters:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 259 of file Layer.php.

00260     {
00261         $collection->addIsFilterableFilter();
00262         return $collection;
00263     }

apply (  ) 

Apply layer Method is colling after apply all filters, can be used for prepare some index data before getting information about existing intexes

Returns:
Mage_Catalog_Model_Layer

Definition at line 141 of file Layer.php.

00142     {
00143         $stateSuffix = '';
00144         foreach ($this->getState()->getFilters() as $filterItem) {
00145             $stateSuffix.= '_'.$filterItem->getFilter()->getRequestVar()
00146                 . '_' . $filterItem->getValueString();
00147         }
00148         if (!empty($stateSuffix)) {
00149             $this->_stateKey = $this->getStateKey().$stateSuffix;
00150         }
00151         return $this;
00152     }

getAggregator (  ) 

Get data aggregation object

Returns:
Mage_CatalogIndex_Model_Aggregation

Definition at line 56 of file Layer.php.

00057     {
00058         return Mage::getSingleton('catalogindex/aggregation');
00059     }

getCurrentCategory (  ) 

Retrieve current category model If no category found in registry, the root will be taken

Returns:
Mage_Catalog_Model_Category

Definition at line 160 of file Layer.php.

00161     {
00162         $category = $this->getData('current_category');
00163         if (is_null($category)) {
00164             if ($category = Mage::registry('current_category')) {
00165                 $this->setData('current_category', $category);
00166             }
00167             else {
00168                 $category = Mage::getModel('catalog/category')->load($this->getCurrentStore()->getRootCategoryId());
00169                 $this->setData('current_category', $category);
00170             }
00171         }
00172         return $category;
00173     }

getCurrentStore (  ) 

Retrieve current store model

Returns:
Mage_Core_Model_Store

Definition at line 205 of file Layer.php.

00206     {
00207         return Mage::app()->getStore();
00208     }

getFilterableAttributes (  ) 

Get collection of all filterable attributes for layer products set

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 215 of file Layer.php.

00216     {
00217         $entity = Mage::getSingleton('eav/config')
00218             ->getEntityType('catalog_product');
00219 
00220         $setIds = $this->_getSetIds();
00221         if (!$setIds) {
00222             return array();
00223         }
00224 
00225         $collection = Mage::getModel('eav/entity_attribute')
00226             ->getCollection()
00227             ->setItemObjectClass('catalog/resource_eav_attribute');
00228 
00229         /* @var $collection Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */
00230         $collection->getSelect()->distinct(true);
00231         $collection
00232             ->setEntityTypeFilter($entity->getId())
00233             ->setAttributeSetFilter($setIds)
00234             ->setOrder('position', 'ASC');
00235         $collection = $this->_prepareAttributeCollection($collection);
00236         $collection->load();
00237 
00238         return $collection;
00239     }

getProductCollection (  ) 

Retrieve current layer product collection

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 95 of file Layer.php.

00096     {
00097         if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
00098             $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
00099         }
00100         else {
00101             $collection = $this->getCurrentCategory()->getProductCollection();
00102             $this->prepareProductCollection($collection);
00103             $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
00104         }
00105 
00106         return $collection;
00107     }

getState (  ) 

Retrieve layer state object

Returns:
Mage_Catalog_Model_Layer_State

Definition at line 270 of file Layer.php.

00271     {
00272         $state = $this->getData('state');
00273         if (is_null($state)) {
00274             Varien_Profiler::start(__METHOD__);
00275             $state = Mage::getModel('catalog/layer_state');
00276             $this->setData('state', $state);
00277             Varien_Profiler::stop(__METHOD__);
00278         }
00279         return $state;
00280     }

getStateKey (  ) 

Get layer state key

Returns:
string

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 66 of file Layer.php.

00067     {
00068         if ($this->_stateKey === null) {
00069             $this->_stateKey = 'STORE_'.Mage::app()->getStore()->getId()
00070                 . '_CAT_'.$this->getCurrentCategory()->getId()
00071                 . '_CUSTGROUP_' . Mage::getSingleton('customer/session')->getCustomerGroupId();
00072         }
00073         return $this->_stateKey;
00074     }

getStateTags ( array additionalTags = array()  ) 

Get default tags for current layer state

Parameters:
array $additionalTags
Returns:
array

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 82 of file Layer.php.

00083     {
00084         $additionalTags = array_merge($additionalTags, array(
00085             Mage_Catalog_Model_Category::CACHE_TAG.$this->getCurrentCategory()->getId()
00086         ));
00087         return $additionalTags;
00088     }

prepareProductCollection ( collection  ) 

Initialize product collection

Parameters:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
Returns:
Mage_Catalog_Model_Layer

Reimplemented in Mage_CatalogSearch_Model_Layer.

Definition at line 115 of file Layer.php.

00116     {
00117         $attributes = Mage::getSingleton('catalog/config')
00118             ->getProductAttributes();
00119         $collection->addAttributeToSelect($attributes)
00120             ->addMinimalPrice()
00121             ->addFinalPrice()
00122             ->addTaxPercents()
00123             //->addStoreFilter()
00124             ;
00125 
00126         Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
00127         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
00128         $collection->addUrlRewrite($this->getCurrentCategory()->getId());
00129 
00130         return $this;
00131     }

setCurrentCategory ( category  ) 

Change current category object

Parameters:
mixed $category
Returns:
Mage_Catalog_Model_Layer

Definition at line 181 of file Layer.php.

00182     {
00183         if (is_numeric($category)) {
00184             $category = Mage::getModel('catalog/category')->load($category);
00185         }
00186         if (!$category instanceof Mage_Catalog_Model_Category) {
00187             Mage::throwException(Mage::helper('catalog')->__('Category must be instance of Mage_Catalog_Model_Category'));
00188         }
00189         if (!$category->getId()) {
00190             Mage::throwException(Mage::helper('catalog')->__('Invalid category'));
00191         }
00192 
00193         if ($category->getId() != $this->getCurrentCategory()->getId()) {
00194             $this->setData('current_category', $category);
00195         }
00196 
00197         return $this;
00198     }


Member Data Documentation

$_productCollections = array() [protected]

Definition at line 42 of file Layer.php.

$_stateKey = null [protected]

Definition at line 49 of file Layer.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