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: class Mage_Catalog_ProductController extends Mage_Core_Controller_Front_Action
34: {
35: 36: 37: 38: 39: 40:
41: protected $_designProductSettingsApplied = array();
42:
43: 44: 45: 46: 47:
48: protected function _initProduct()
49: {
50: $categoryId = (int) $this->getRequest()->getParam('category', false);
51: $productId = (int) $this->getRequest()->getParam('id');
52:
53: $params = new Varien_Object();
54: $params->setCategoryId($categoryId);
55:
56: return Mage::helper('catalog/product')->initProduct($productId, $this, $params);
57: }
58:
59: 60: 61: 62: 63: 64:
65: protected function _initProductLayout($product)
66: {
67: Mage::helper('catalog/product_view')->initProductLayout($product, $this);
68: return $this;
69: }
70:
71: 72: 73: 74: 75: 76: 77: 78: 79:
80: protected function _applyCustomDesignSettings($object, $update)
81: {
82: if ($object instanceof Mage_Catalog_Model_Category) {
83:
84: if ($object->getCustomUseParentSettings()) {
85: $parentCategory = $object->getParentCategory();
86: if ($parentCategory && $parentCategory->getId() && $parentCategory->getLevel() > 1) {
87: $this->_applyCustomDesignSettings($parentCategory, $update);
88: }
89: return;
90: }
91:
92:
93: if (!$object->getCustomApplyToProducts()) {
94: return;
95: }
96: }
97:
98: if ($this->_designProductSettingsApplied) {
99: return;
100: }
101:
102: $date = $object->getCustomDesignDate();
103: if (array_key_exists('from', $date) && array_key_exists('to', $date)
104: && Mage::app()->getLocale()->isStoreDateInInterval(null, $date['from'], $date['to'])
105: ) {
106: if ($object->getPageLayout()) {
107: $this->_designProductSettingsApplied['layout'] = $object->getPageLayout();
108: }
109: $this->_designProductSettingsApplied['update'] = $object->getCustomLayoutUpdate();
110: }
111: }
112:
113: 114: 115:
116: public function viewAction()
117: {
118:
119: $categoryId = (int) $this->getRequest()->getParam('category', false);
120: $productId = (int) $this->getRequest()->getParam('id');
121: $specifyOptions = $this->getRequest()->getParam('options');
122:
123:
124: $viewHelper = Mage::helper('catalog/product_view');
125:
126: $params = new Varien_Object();
127: $params->setCategoryId($categoryId);
128: $params->setSpecifyOptions($specifyOptions);
129:
130:
131: try {
132: $viewHelper->prepareAndRender($productId, $this, $params);
133: } catch (Exception $e) {
134: if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) {
135: if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) {
136: $this->_redirect('');
137: } elseif (!$this->getResponse()->isRedirect()) {
138: $this->_forward('noRoute');
139: }
140: } else {
141: Mage::logException($e);
142: $this->_forward('noRoute');
143: }
144: }
145: }
146:
147: 148: 149:
150: public function galleryAction()
151: {
152: if (!$this->_initProduct()) {
153: if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) {
154: $this->_redirect('');
155: } elseif (!$this->getResponse()->isRedirect()) {
156: $this->_forward('noRoute');
157: }
158: return;
159: }
160: $this->loadLayout();
161: $this->renderLayout();
162: }
163:
164: 165: 166: 167: 168:
169: public function imageAction()
170: {
171: 172: 173:
174: $this->_forward('noRoute');
175: }
176: }
177: