Public Member Functions | |
viewAction () | |
galleryAction () | |
imageAction () | |
Protected Member Functions | |
_initProduct () | |
_initProductLayout ($product) |
Definition at line 33 of file ProductController.php.
_initProduct | ( | ) | [protected] |
Initialize requested product object
Definition at line 40 of file ProductController.php.
00041 { 00042 Mage::dispatchEvent('catalog_controller_product_init_before', array('controller_action'=>$this)); 00043 $categoryId = (int) $this->getRequest()->getParam('category', false); 00044 $productId = (int) $this->getRequest()->getParam('id'); 00045 00046 if (!$productId) { 00047 return false; 00048 } 00049 00050 $product = Mage::getModel('catalog/product') 00051 ->setStoreId(Mage::app()->getStore()->getId()) 00052 ->load($productId); 00053 00054 if (!Mage::helper('catalog/product')->canShow($product)) { 00055 return false; 00056 } 00057 if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) { 00058 return false; 00059 } 00060 00061 $category = null; 00062 if ($categoryId) { 00063 $category = Mage::getModel('catalog/category')->load($categoryId); 00064 $product->setCategory($category); 00065 Mage::register('current_category', $category); 00066 } 00067 elseif ($categoryId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId()) { 00068 if ($product->canBeShowInCategory($categoryId)) { 00069 $category = Mage::getModel('catalog/category')->load($categoryId); 00070 $product->setCategory($category); 00071 Mage::register('current_category', $category); 00072 } 00073 } 00074 00075 00076 Mage::register('current_product', $product); 00077 Mage::register('product', $product); 00078 00079 try { 00080 Mage::dispatchEvent('catalog_controller_product_init', array('product'=>$product)); 00081 Mage::dispatchEvent('catalog_controller_product_init_after', array('product'=>$product, 'controller_action' => $this)); 00082 } catch (Mage_Core_Exception $e) { 00083 Mage::logException($e); 00084 return false; 00085 } 00086 00087 return $product; 00088 }
_initProductLayout | ( | $ | product | ) | [protected] |
Initialize product view layout
Mage_Catalog_Model_Product | $product |
Definition at line 96 of file ProductController.php.
00097 { 00098 $update = $this->getLayout()->getUpdate(); 00099 $update->addHandle('default'); 00100 $this->addActionLayoutHandles(); 00101 00102 $update->addHandle('PRODUCT_TYPE_'.$product->getTypeId()); 00103 $update->addHandle('PRODUCT_'.$product->getId()); 00104 00105 if ($product->getPageLayout()) { 00106 $this->getLayout()->helper('page/layout') 00107 ->applyHandle($product->getPageLayout()); 00108 } 00109 00110 $this->loadLayoutUpdates(); 00111 00112 00113 $update->addUpdate($product->getCustomLayoutUpdate()); 00114 00115 $this->generateLayoutXml()->generateLayoutBlocks(); 00116 00117 if ($product->getPageLayout()) { 00118 $this->getLayout()->helper('page/layout') 00119 ->applyTemplate($product->getPageLayout()); 00120 } 00121 00122 $currentCategory = Mage::registry('current_category'); 00123 if ($root = $this->getLayout()->getBlock('root')) { 00124 $root->addBodyClass('product-'.$product->getUrlKey()); 00125 if ($currentCategory instanceof Mage_Catalog_Model_Category) { 00126 $root->addBodyClass('categorypath-'.$currentCategory->getUrlPath()) 00127 ->addBodyClass('category-'.$currentCategory->getUrlKey()); 00128 } 00129 } 00130 return $this; 00131 }
galleryAction | ( | ) |
View product gallery action
Definition at line 167 of file ProductController.php.
00168 { 00169 if (!$this->_initProduct()) { 00170 if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { 00171 $this->_redirect(''); 00172 } elseif (!$this->getResponse()->isRedirect()) { 00173 $this->_forward('noRoute'); 00174 } 00175 return; 00176 } 00177 $this->loadLayout(); 00178 $this->renderLayout(); 00179 }
imageAction | ( | ) |
Display product image action
Definition at line 184 of file ProductController.php.
00185 { 00186 $size = (string) $this->getRequest()->getParam('size'); 00187 if ($size) { 00188 $imageFile = preg_replace("#.*/catalog/product/image/size/[0-9]*x[0-9]*#", '', $this->getRequest()->getRequestUri()); 00189 } else { 00190 $imageFile = preg_replace("#.*/catalog/product/image#", '', $this->getRequest()->getRequestUri()); 00191 } 00192 00193 if (!strstr($imageFile, '.')) { 00194 $this->_forward('noRoute'); 00195 return; 00196 } 00197 00198 try { 00199 $imageModel = Mage::getModel('catalog/product_image'); 00200 $imageModel->setSize($size) 00201 ->setBaseFile($imageFile) 00202 ->resize() 00203 ->setWatermark( Mage::getStoreConfig('catalog/watermark/image') ) 00204 ->saveFile() 00205 ->push(); 00206 } catch( Exception $e ) { 00207 $this->_forward('noRoute'); 00208 } 00209 }
viewAction | ( | ) |
View product action
Definition at line 136 of file ProductController.php.
00137 { 00138 if ($product = $this->_initProduct()) { 00139 Mage::dispatchEvent('catalog_controller_product_view', array('product'=>$product)); 00140 00141 if ($this->getRequest()->getParam('options')) { 00142 $notice = $product->getTypeInstance(true)->getSpecifyOptionMessage(); 00143 Mage::getSingleton('catalog/session')->addNotice($notice); 00144 } 00145 00146 Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId()); 00147 Mage::getModel('catalog/design')->applyDesign($product, Mage_Catalog_Model_Design::APPLY_FOR_PRODUCT); 00148 00149 $this->_initProductLayout($product); 00150 $this->_initLayoutMessages('catalog/session'); 00151 $this->_initLayoutMessages('tag/session'); 00152 $this->_initLayoutMessages('checkout/session'); 00153 $this->renderLayout(); 00154 } 00155 else { 00156 if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { 00157 $this->_redirect(''); 00158 } elseif (!$this->getResponse()->isRedirect()) { 00159 $this->_forward('noRoute'); 00160 } 00161 } 00162 }