| 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/Model/ |
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)
*/
/**
* Catalog Custom Category design Model
*
* @category Mage
* @package Mage_Catalog
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Catalog_Model_Design extends Mage_Core_Model_Abstract
{
const APPLY_FOR_PRODUCT = 1;
const APPLY_FOR_CATEGORY = 2;
/**
* Category / Custom Design / Apply To constants
*
*/
const CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE = 1;
const CATEGORY_APPLY_CATEGORY_ONLY = 2;
const CATEGORY_APPLY_CATEGORY_AND_PRODUCT_ONLY = 3;
const CATEGORY_APPLY_CATEGORY_RECURSIVE = 4;
/**
* Apply design from catalog object
*
* @param array|Mage_Catalog_Model_Category|Mage_Catalog_Model_Product $object
* @param int $calledFrom
* @return Mage_Catalog_Model_Design
*/
public function applyDesign($object, $calledFrom = 0)
{
if ($calledFrom != self::APPLY_FOR_CATEGORY && $calledFrom != self::APPLY_FOR_PRODUCT) {
return $this;
}
if (Mage::helper('catalog/category_flat')->isEnabled()) {
$this->_applyDesign($object, $calledFrom);
} else {
$this->_applyDesignRecursively($object, $calledFrom);
}
return $this;
}
/**
* Apply package and theme
*
* @param string $package
* @param string $theme
*/
protected function _apply($package, $theme)
{
Mage::getSingleton('core/design_package')
->setPackageName($package)
->setTheme($theme);
}
/**
* Check is allow apply for
*
* @param int $applyForObject
* @param int $applyTo
* @param int $pass
* @return bool
*/
protected function _isApplyFor($applyForObject, $applyTo, $pass = 0)
{
$hasError = false;
if ($pass == 0) {
switch ($applyForObject) {
case self::APPLY_FOR_CATEGORY:
break;
case self::APPLY_FOR_PRODUCT:
$validApplyTo = array(
self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE,
self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_ONLY
);
if ($applyTo && !in_array($applyTo, $validApplyTo)) {
$hasError = true;
}
break;
default:
$hasError = true;
break;
}
}
else {
switch ($applyForObject) {
case self::APPLY_FOR_CATEGORY:
$validApplyTo = array(
self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE,
self::CATEGORY_APPLY_CATEGORY_RECURSIVE
);
if ($applyTo && !in_array($applyTo, $validApplyTo)) {
$hasError = true;
}
break;
case self::APPLY_FOR_PRODUCT:
$validApplyTo = array(
self::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE
);
if ($applyTo && !in_array($applyTo, $validApplyTo)) {
$hasError = true;
}
break;
default:
$hasError = true;
break;
}
}
return !$hasError;
}
/**
* Check and apply design
*
* @param string $design
* @param array $date
*/
protected function _isApplyDesign($design, array $date)
{
if (!array_key_exists('from', $date) || !array_key_exists('to', $date)) {
return false;
}
$designInfo = explode("/", $design);
if (count($designInfo) != 2) {
return false;
}
// define package and theme
$package = $designInfo[0];
$theme = $designInfo[1];
// compare dates
if (Mage::app()->getLocale()->isStoreDateInInterval(null, $date['from'], $date['to'])) {
$this->_apply($package, $theme);
return true;
}
return false;
}
/**
* Apply design recursively (if using EAV)
*
* @param Varien_Object $object
* @param int $calledFrom
* @return Mage_Catalog_Model_Design
*/
protected function _applyDesignRecursively($object, $calledFrom = 0, $pass = 0)
{
$design = $object->getCustomDesign();
$date = $object->getCustomDesignDate();
$applyTo = $object->getCustomDesignApply();
$checkAndApply = $this->_isApplyFor($calledFrom, $applyTo, $pass)
&& $this->_isApplyDesign($design, $date);
if ($checkAndApply) {
return $this;
}
$pass ++;
$category = null;
if ($object instanceof Mage_Catalog_Model_Product) {
$category = $object->getCategory();
$pass --;
}
elseif ($object instanceof Mage_Catalog_Model_Category) {
$category = $object->getParentCategory();
}
if ($category && $category->getId()){
$this->_applyDesignRecursively($category, $calledFrom, $pass);
}
return $this;
}
/**
* Apply design (if using Flat Category)
*
* @param Varien_Object|array $designUpdateData
* @param int $calledFrom
* @param bool $loaded
* @return Mage_Catalog_Model_Design
*/
protected function _applyDesign($designUpdateData, $calledFrom = 0, $loaded = false, $pass = 0)
{
$objects = array();
if (is_object($designUpdateData)) {
$objects = array($designUpdateData);
} elseif (is_array($designUpdateData)) {
$objects = &$designUpdateData;
}
foreach ($objects as $object) {
$design = $object->getCustomDesign();
$date = $object->getCustomDesignDate();
$applyTo = $object->getCustomDesignApply();
$checkAndApply = $this->_isApplyFor($calledFrom, $applyTo, $pass)
&& $this->_isApplyDesign($design, $date);
if ($checkAndApply) {
return $this;
}
}
$pass ++;
if (false === $loaded && is_object($designUpdateData)) {
$_designUpdateData = array();
if ($designUpdateData instanceof Mage_Catalog_Model_Product) {
$_category = $designUpdateData->getCategory();
$_designUpdateData = array_merge(
$_designUpdateData, array($_category)
);
$pass --;
} elseif ($designUpdateData instanceof Mage_Catalog_Model_Category) {
$_category = &$designUpdateData;
}
if ($_category && $_category->getId()) {
$_designUpdateData = array_merge(
$_designUpdateData,
$_category->getResource()->getDesignUpdateData($_category)
);
$this->_applyDesign($_designUpdateData, $calledFrom, true, $pass);
}
}
return $this;
}
}