1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Catalog_CategoryController extends Mage_Core_Controller_Front_Action
35: {
36: 37: 38: 39: 40:
41: protected function _initCatagory()
42: {
43: Mage::dispatchEvent('catalog_controller_category_init_before', array('controller_action' => $this));
44: $categoryId = (int) $this->getRequest()->getParam('id', false);
45: if (!$categoryId) {
46: return false;
47: }
48:
49: $category = Mage::getModel('catalog/category')
50: ->setStoreId(Mage::app()->getStore()->getId())
51: ->load($categoryId);
52:
53: if (!Mage::helper('catalog/category')->canShow($category)) {
54: return false;
55: }
56: Mage::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId());
57: Mage::register('current_category', $category);
58: try {
59: Mage::dispatchEvent(
60: 'catalog_controller_category_init_after',
61: array(
62: 'category' => $category,
63: 'controller_action' => $this
64: )
65: );
66: } catch (Mage_Core_Exception $e) {
67: Mage::logException($e);
68: return false;
69: }
70:
71: return $category;
72: }
73:
74: 75: 76: 77: 78: 79: 80: 81: 82: 83:
84: protected function _applyCustomDesignSettings($category, $update)
85: {
86: if ($category->getCustomUseParentSettings() && $category->getLevel() > 1) {
87: $parentCategory = $category->getParentCategory();
88: if ($parentCategory && $parentCategory->getId()) {
89: return $this->_applyCustomDesignSettings($parentCategory, $update);
90: }
91: }
92:
93: $validityDate = $category->getCustomDesignDate();
94:
95: if (array_key_exists('from', $validityDate) &&
96: array_key_exists('to', $validityDate) &&
97: Mage::app()->getLocale()->isStoreDateInInterval(null, $validityDate['from'], $validityDate['to'])
98: ) {
99: if ($category->getPageLayout()) {
100: $this->getLayout()->helper('page/layout')
101: ->applyHandle($category->getPageLayout());
102: }
103: $update->addUpdate($category->getCustomLayoutUpdate());
104: }
105:
106: return $this;
107: }
108:
109: 110: 111:
112: public function viewAction()
113: {
114: if ($category = $this->_initCatagory()) {
115: $design = Mage::getSingleton('catalog/design');
116: $settings = $design->getDesignSettings($category);
117:
118:
119: if ($settings->getCustomDesign()) {
120: $design->applyCustomDesign($settings->getCustomDesign());
121: }
122:
123: Mage::getSingleton('catalog/session')->setLastViewedCategoryId($category->getId());
124:
125: $update = $this->getLayout()->getUpdate();
126: $update->addHandle('default');
127:
128: if (!$category->hasChildren()) {
129: $update->addHandle('catalog_category_layered_nochildren');
130: }
131:
132: $this->addActionLayoutHandles();
133: $update->addHandle($category->getLayoutUpdateHandle());
134: $update->addHandle('CATEGORY_' . $category->getId());
135: $this->loadLayoutUpdates();
136:
137:
138: if ($layoutUpdates = $settings->getLayoutUpdates()) {
139: if (is_array($layoutUpdates)) {
140: foreach($layoutUpdates as $layoutUpdate) {
141: $update->addUpdate($layoutUpdate);
142: }
143: }
144: }
145:
146: $this->generateLayoutXml()->generateLayoutBlocks();
147:
148: if ($settings->getPageLayout()) {
149: $this->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout());
150: }
151:
152: if ($root = $this->getLayout()->getBlock('root')) {
153: $root->addBodyClass('categorypath-' . $category->getUrlPath())
154: ->addBodyClass('category-' . $category->getUrlKey());
155: }
156:
157: $this->_initLayoutMessages('catalog/session');
158: $this->_initLayoutMessages('checkout/session');
159: $this->renderLayout();
160: }
161: elseif (!$this->getResponse()->isRedirect()) {
162: $this->_forward('noRoute');
163: }
164: }
165: }
166: