0byt3m1n1
Path:
/
data
/
applications
/
aps
/
magento
/
1.1.3-2
/
standard
/
htdocs
/
app
/
code
/
core
/
Mage
/
Catalog
/
Model
/
[
Home
]
File: Layer.php
<?php /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * @category Mage * @package Mage_Catalog * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog view layer model * * @category Mage * @package Mage_Catalog * @author Magento Core Team <core@magentocommerce.com> */ class Mage_Catalog_Model_Layer extends Varien_Object { /** * Retrieve current layer product collection * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getProductCollection() { $collection = $this->getData('product_collection'); if (is_null($collection)) { $collection = $this->getCurrentCategory()->getProductCollection(); $this->prepareProductCollection($collection); $this->setData('product_collection', $collection); } return $collection; } /** * Initialize product collection * * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection * @return Mage_Catalog_Model_Layer */ public function prepareProductCollection($collection) { $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->addStoreFilter(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); $collection->addUrlRewrite($this->getCurrentCategory()->getId()); return $this; } /** * Apply layer * Method is colling after apply all filters, can be used * for prepare some index data before getting information * about existing intexes * * @return Mage_Catalog_Model_Layer */ public function apply() { return $this; } /** * Retrieve current category model * * @return Mage_Catalog_Model_Category */ public function getCurrentCategory() { $category = $this->getData('current_category'); if (is_null($category)) { if ($category = Mage::registry('current_category')) { $this->setData('current_category', $category); } else { $category = false; $this->setData('current_category', $category); } } return $category; } /** * Retrieve current store model * * @return Mage_Core_Model_Store */ public function getCurrentStore() { return Mage::app()->getStore(); } /** * Enter description here... * * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ public function getFilterableAttributes() { $entity = $this->getProductCollection()->getEntity(); $setIds = $this->getProductCollection()->getSetIds(); if (!$setIds) return array(); $collection = Mage::getModel('eav/entity_attribute')->getCollection() ->setItemObjectClass('catalog/resource_eav_attribute'); /* @var $collection Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ $collection->getSelect()->distinct(true); $collection->setEntityTypeFilter($entity->getTypeId()) ->setAttributeSetFilter($setIds) ->addIsFilterableFilter() ->setOrder('position', 'ASC') ->load(); foreach ($collection as $item) { Mage::getResourceSingleton('catalog/product')->getAttribute($item); $item->setEntity($entity); } return $collection; } /** * Retrieve layer state object * * @return Mage_Catalog_Model_Layer_State */ public function getState() { $state = $this->getData('state'); if (is_null($state)) { $state = Mage::getModel('catalog/layer_state'); $this->setData('state', $state); } return $state; } }