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) 2012 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: /**
28: * Category View block
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Catalog_Block_Category_View extends Mage_Core_Block_Template
35: {
36: protected function _prepareLayout()
37: {
38: parent::_prepareLayout();
39:
40: $this->getLayout()->createBlock('catalog/breadcrumbs');
41:
42: if ($headBlock = $this->getLayout()->getBlock('head')) {
43: $category = $this->getCurrentCategory();
44: if ($title = $category->getMetaTitle()) {
45: $headBlock->setTitle($title);
46: }
47: if ($description = $category->getMetaDescription()) {
48: $headBlock->setDescription($description);
49: }
50: if ($keywords = $category->getMetaKeywords()) {
51: $headBlock->setKeywords($keywords);
52: }
53: if ($this->helper('catalog/category')->canUseCanonicalTag()) {
54: $headBlock->addLinkRel('canonical', $category->getUrl());
55: }
56: /*
57: want to show rss feed in the url
58: */
59: if ($this->IsRssCatalogEnable() && $this->IsTopCategory()) {
60: $title = $this->helper('rss')->__('%s RSS Feed',$this->getCurrentCategory()->getName());
61: $headBlock->addItem('rss', $this->getRssLink(), 'title="'.$title.'"');
62: }
63: }
64:
65: return $this;
66: }
67:
68: public function IsRssCatalogEnable()
69: {
70: return Mage::getStoreConfig('rss/catalog/category');
71: }
72:
73: public function IsTopCategory()
74: {
75: return $this->getCurrentCategory()->getLevel()==2;
76: }
77:
78: public function getRssLink()
79: {
80: return Mage::getUrl('rss/catalog/category',array('cid' => $this->getCurrentCategory()->getId(), 'store_id' => Mage::app()->getStore()->getId()));
81: }
82:
83: public function getProductListHtml()
84: {
85: return $this->getChildHtml('product_list');
86: }
87:
88: /**
89: * Retrieve current category model object
90: *
91: * @return Mage_Catalog_Model_Category
92: */
93: public function getCurrentCategory()
94: {
95: if (!$this->hasData('current_category')) {
96: $this->setData('current_category', Mage::registry('current_category'));
97: }
98: return $this->getData('current_category');
99: }
100:
101: public function getCmsBlockHtml()
102: {
103: if (!$this->getData('cms_block_html')) {
104: $html = $this->getLayout()->createBlock('cms/block')
105: ->setBlockId($this->getCurrentCategory()->getLandingPage())
106: ->toHtml();
107: $this->setData('cms_block_html', $html);
108: }
109: return $this->getData('cms_block_html');
110: }
111:
112: /**
113: * Check if category display mode is "Products Only"
114: * @return bool
115: */
116: public function isProductMode()
117: {
118: return $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_PRODUCT;
119: }
120:
121: /**
122: * Check if category display mode is "Static Block and Products"
123: * @return bool
124: */
125: public function isMixedMode()
126: {
127: return $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_MIXED;
128: }
129:
130: /**
131: * Check if category display mode is "Static Block Only"
132: * For anchor category with applied filter Static Block Only mode not allowed
133: *
134: * @return bool
135: */
136: public function isContentMode()
137: {
138: $category = $this->getCurrentCategory();
139: $res = false;
140: if ($category->getDisplayMode()==Mage_Catalog_Model_Category::DM_PAGE) {
141: $res = true;
142: if ($category->getIsAnchor()) {
143: $state = Mage::getSingleton('catalog/layer')->getState();
144: if ($state && $state->getFilters()) {
145: $res = false;
146: }
147: }
148: }
149: return $res;
150: }
151: }
152: