PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/app/code/core/Mage/Catalog/Block/Layer/View.php

https://github.com/chrisroseuk/magento19_dev
PHP | 255 lines | 107 code | 29 blank | 119 comment | 8 complexity | 7c92a839423cdcc10d4b5b8303e84cc9 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Catalog
  23. * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Catalog layered navigation view block
  28. *
  29. * @category Mage
  30. * @package Mage_Catalog
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Catalog_Block_Layer_View extends Mage_Core_Block_Template
  34. {
  35. /**
  36. * State block name
  37. *
  38. * @var string
  39. */
  40. protected $_stateBlockName;
  41. /**
  42. * Category Block Name
  43. *
  44. * @var string
  45. */
  46. protected $_categoryBlockName;
  47. /**
  48. * Attribute Filter Block Name
  49. *
  50. * @var string
  51. */
  52. protected $_attributeFilterBlockName;
  53. /**
  54. * Price Filter Block Name
  55. *
  56. * @var string
  57. */
  58. protected $_priceFilterBlockName;
  59. /**
  60. * Decimal Filter Block Name
  61. *
  62. * @var string
  63. */
  64. protected $_decimalFilterBlockName;
  65. /**
  66. * Internal constructor
  67. */
  68. protected function _construct()
  69. {
  70. parent::_construct();
  71. $this->_initBlocks();
  72. }
  73. /**
  74. * Initialize blocks names
  75. */
  76. protected function _initBlocks()
  77. {
  78. $this->_stateBlockName = 'catalog/layer_state';
  79. $this->_categoryBlockName = 'catalog/layer_filter_category';
  80. $this->_attributeFilterBlockName = 'catalog/layer_filter_attribute';
  81. $this->_priceFilterBlockName = 'catalog/layer_filter_price';
  82. $this->_decimalFilterBlockName = 'catalog/layer_filter_decimal';
  83. }
  84. /**
  85. * Get attribute filter block name
  86. *
  87. * @deprecated after 1.4.1.0
  88. *
  89. * @return string
  90. */
  91. protected function _getAttributeFilterBlockName()
  92. {
  93. return 'catalog/layer_filter_attribute';
  94. }
  95. /**
  96. * Prepare child blocks
  97. *
  98. * @return Mage_Catalog_Block_Layer_View
  99. */
  100. protected function _prepareLayout()
  101. {
  102. $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
  103. ->setLayer($this->getLayer());
  104. $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
  105. ->setLayer($this->getLayer())
  106. ->init();
  107. $this->setChild('layer_state', $stateBlock);
  108. $this->setChild('category_filter', $categoryBlock);
  109. $filterableAttributes = $this->_getFilterableAttributes();
  110. foreach ($filterableAttributes as $attribute) {
  111. if ($attribute->getAttributeCode() == 'price') {
  112. $filterBlockName = $this->_priceFilterBlockName;
  113. } elseif ($attribute->getBackendType() == 'decimal') {
  114. $filterBlockName = $this->_decimalFilterBlockName;
  115. } else {
  116. $filterBlockName = $this->_attributeFilterBlockName;
  117. }
  118. $this->setChild($attribute->getAttributeCode() . '_filter',
  119. $this->getLayout()->createBlock($filterBlockName)
  120. ->setLayer($this->getLayer())
  121. ->setAttributeModel($attribute)
  122. ->init());
  123. }
  124. $this->getLayer()->apply();
  125. return parent::_prepareLayout();
  126. }
  127. /**
  128. * Get layer object
  129. *
  130. * @return Mage_Catalog_Model_Layer
  131. */
  132. public function getLayer()
  133. {
  134. return Mage::getSingleton('catalog/layer');
  135. }
  136. /**
  137. * Get all fiterable attributes of current category
  138. *
  139. * @return array
  140. */
  141. protected function _getFilterableAttributes()
  142. {
  143. $attributes = $this->getData('_filterable_attributes');
  144. if (is_null($attributes)) {
  145. $attributes = $this->getLayer()->getFilterableAttributes();
  146. $this->setData('_filterable_attributes', $attributes);
  147. }
  148. return $attributes;
  149. }
  150. /**
  151. * Get layered navigation state html
  152. *
  153. * @return string
  154. */
  155. public function getStateHtml()
  156. {
  157. return $this->getChildHtml('layer_state');
  158. }
  159. /**
  160. * Get all layer filters
  161. *
  162. * @return array
  163. */
  164. public function getFilters()
  165. {
  166. $filters = array();
  167. if ($categoryFilter = $this->_getCategoryFilter()) {
  168. $filters[] = $categoryFilter;
  169. }
  170. $filterableAttributes = $this->_getFilterableAttributes();
  171. foreach ($filterableAttributes as $attribute) {
  172. $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
  173. }
  174. return $filters;
  175. }
  176. /**
  177. * Get category filter block
  178. *
  179. * @return Mage_Catalog_Block_Layer_Filter_Category
  180. */
  181. protected function _getCategoryFilter()
  182. {
  183. return $this->getChild('category_filter');
  184. }
  185. /**
  186. * Check availability display layer options
  187. *
  188. * @return bool
  189. */
  190. public function canShowOptions()
  191. {
  192. foreach ($this->getFilters() as $filter) {
  193. if ($filter->getItemsCount()) {
  194. return true;
  195. }
  196. }
  197. return false;
  198. }
  199. /**
  200. * Check availability display layer block
  201. *
  202. * @return bool
  203. */
  204. public function canShowBlock()
  205. {
  206. return $this->canShowOptions() || count($this->getLayer()->getState()->getFilters());
  207. }
  208. /**
  209. * Retrieve Price Filter block
  210. *
  211. * @return Mage_Catalog_Block_Layer_Filter_Price
  212. */
  213. protected function _getPriceFilter()
  214. {
  215. return $this->getChild('_price_filter');
  216. }
  217. /**
  218. * Get url for 'Clear All' link
  219. *
  220. * @return string
  221. */
  222. public function getClearUrl()
  223. {
  224. return $this->getChild('layer_state')->getClearUrl();
  225. }
  226. }