00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_CatalogSearch 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 class Mage_CatalogSearch_Model_Layer extends Mage_Catalog_Model_Layer 00028 { 00029 const XML_PATH_DISPLAY_LAYER_COUNT = 'catalog/search/use_layered_navigation_count'; 00030 00031 /** 00032 * Get current layer product collection 00033 * 00034 * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection 00035 */ 00036 public function getProductCollection() 00037 { 00038 if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) { 00039 $collection = $this->_productCollections[$this->getCurrentCategory()->getId()]; 00040 } 00041 else { 00042 $collection = Mage::getResourceModel('catalogsearch/fulltext_collection'); 00043 $this->prepareProductCollection($collection); 00044 $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection; 00045 } 00046 00047 return $collection; 00048 } 00049 00050 /** 00051 * Prepare product collection 00052 * 00053 * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection 00054 * @return Mage_Catalog_Model_Layer 00055 */ 00056 public function prepareProductCollection($collection) 00057 { 00058 $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) 00059 ->addSearchFilter(Mage::helper('catalogSearch')->getEscapedQueryText()) 00060 ->setStore(Mage::app()->getStore()) 00061 ->addMinimalPrice() 00062 ->addFinalPrice() 00063 ->addTaxPercents() 00064 ->addStoreFilter() 00065 ->addUrlRewrite(); 00066 00067 Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); 00068 Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection); 00069 return $this; 00070 } 00071 00072 /** 00073 * Get layer state key 00074 * 00075 * @return string 00076 */ 00077 public function getStateKey() 00078 { 00079 if ($this->_stateKey === null) { 00080 $this->_stateKey = 'Q_'.Mage::helper('catalogSearch')->getQuery()->getId() 00081 .'_'.parent::getStateKey(); 00082 } 00083 return $this->_stateKey; 00084 } 00085 00086 /** 00087 * Get default tags for current layer state 00088 * 00089 * @param array $additionalTags 00090 * @return array 00091 */ 00092 public function getStateTags(array $additionalTags = array()) 00093 { 00094 $additionalTags = parent::getStateTags($additionalTags); 00095 $additionalTags[] = Mage_CatalogSearch_Model_Query::CACHE_TAG; 00096 return $additionalTags; 00097 } 00098 00099 /** 00100 * Add filters to attribute collection 00101 * 00102 * @param Mage_Eav_Model_Mysql4_Entity_Attribute_Collection $collection 00103 * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection 00104 */ 00105 protected function _prepareAttributeCollection($collection) 00106 { 00107 $collection->addIsFilterableInSearchFilter(); 00108 return $collection; 00109 } 00110 00111 /** 00112 * Prepare attribute for use in layered navigation 00113 * 00114 * @param Mage_Eav_Model_Entity_Attribute $attribute 00115 * @return Mage_Eav_Model_Entity_Attribute 00116 */ 00117 protected function _prepareAttribute($attribute) 00118 { 00119 $attribute = parent::_prepareAttribute($attribute); 00120 $attribute->setIsFilterable(Mage_Catalog_Model_Layer_Filter_Attribute::OPTIONS_ONLY_WITH_RESULTS); 00121 return $attribute; 00122 } 00123 }