| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/awebpaca/boutiques/app/code/core/Mage/Catalog/controllers/ |
Upload File : |
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Product controller
*
* @category Mage
* @package Mage_Catalog
*/
class Mage_Catalog_ProductController extends Mage_Core_Controller_Front_Action
{
/**
* Initialize requested product object
*
* @return Mage_Catalog_Model_Product
*/
protected function _initProduct()
{
Mage::dispatchEvent('catalog_controller_product_init_before', array('controller_action'=>$this));
$categoryId = (int) $this->getRequest()->getParam('category', false);
$productId = (int) $this->getRequest()->getParam('id');
if (!$productId) {
return false;
}
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);
if (!Mage::helper('catalog/product')->canShow($product)) {
return false;
}
if (!in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
return false;
}
$category = null;
if ($categoryId) {
$category = Mage::getModel('catalog/category')->load($categoryId);
$product->setCategory($category);
Mage::register('current_category', $category);
}
elseif ($categoryId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId()) {
if ($product->canBeShowInCategory($categoryId)) {
$category = Mage::getModel('catalog/category')->load($categoryId);
$product->setCategory($category);
Mage::register('current_category', $category);
}
}
Mage::register('current_product', $product);
Mage::register('product', $product);
try {
Mage::dispatchEvent('catalog_controller_product_init', array('product'=>$product));
Mage::dispatchEvent('catalog_controller_product_init_after', array('product'=>$product, 'controller_action' => $this));
} catch (Mage_Core_Exception $e) {
Mage::logException($e);
return false;
}
return $product;
}
/**
* Initialize product view layout
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Catalog_ProductController
*/
protected function _initProductLayout($product)
{
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$update->addHandle('PRODUCT_TYPE_'.$product->getTypeId());
$update->addHandle('PRODUCT_'.$product->getId());
if ($product->getPageLayout()) {
$this->getLayout()->helper('page/layout')
->applyHandle($product->getPageLayout());
}
$this->loadLayoutUpdates();
$update->addUpdate($product->getCustomLayoutUpdate());
$this->generateLayoutXml()->generateLayoutBlocks();
if ($product->getPageLayout()) {
$this->getLayout()->helper('page/layout')
->applyTemplate($product->getPageLayout());
}
$currentCategory = Mage::registry('current_category');
if ($root = $this->getLayout()->getBlock('root')) {
$root->addBodyClass('product-'.$product->getUrlKey());
if ($currentCategory instanceof Mage_Catalog_Model_Category) {
$root->addBodyClass('categorypath-'.$currentCategory->getUrlPath())
->addBodyClass('category-'.$currentCategory->getUrlKey());
}
}
return $this;
}
/**
* View product action
*/
public function viewAction()
{
if ($product = $this->_initProduct()) {
Mage::dispatchEvent('catalog_controller_product_view', array('product'=>$product));
if ($this->getRequest()->getParam('options')) {
$notice = $product->getTypeInstance(true)->getSpecifyOptionMessage();
Mage::getSingleton('catalog/session')->addNotice($notice);
}
Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId());
Mage::getModel('catalog/design')->applyDesign($product, Mage_Catalog_Model_Design::APPLY_FOR_PRODUCT);
$this->_initProductLayout($product);
$this->_initLayoutMessages('catalog/session');
$this->_initLayoutMessages('tag/session');
$this->_initLayoutMessages('checkout/session');
$this->renderLayout();
}
else {
if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) {
$this->_redirect('');
} elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
}
}
/**
* View product gallery action
*/
public function galleryAction()
{
if (!$this->_initProduct()) {
if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) {
$this->_redirect('');
} elseif (!$this->getResponse()->isRedirect()) {
$this->_forward('noRoute');
}
return;
}
$this->loadLayout();
$this->renderLayout();
}
/**
* Display product image action
*/
public function imageAction()
{
$size = (string) $this->getRequest()->getParam('size');
if ($size) {
$imageFile = preg_replace("#.*/catalog/product/image/size/[0-9]*x[0-9]*#", '', $this->getRequest()->getRequestUri());
} else {
$imageFile = preg_replace("#.*/catalog/product/image#", '', $this->getRequest()->getRequestUri());
}
if (!strstr($imageFile, '.')) {
$this->_forward('noRoute');
return;
}
try {
$imageModel = Mage::getModel('catalog/product_image');
$imageModel->setSize($size)
->setBaseFile($imageFile)
->resize()
->setWatermark( Mage::getStoreConfig('catalog/watermark/image') )
->saveFile()
->push();
} catch( Exception $e ) {
$this->_forward('noRoute');
}
}
}