// Context part 4

This commit is contained in:
tDidierjean
2011-07-13 07:51:09 +00:00
parent daec4c3e93
commit 375607f8a5
3 changed files with 18 additions and 16 deletions
+7 -6
View File
@@ -81,10 +81,12 @@ class FrontControllerCore
if (self::$initialized)
return;
self::$initialized = true;
$context = Context::getContext();
$this->id_current_shop = Context::getContext()->shop->getID();
$this->id_current_group_shop = Context::getContext()->shop->getGroupID();
$this->css_files = array();
$this->js_files = array();
@@ -233,7 +235,8 @@ class FrontControllerCore
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$link = new Link($protocol_link, $protocol_content);
$context->link = $link;
$context->language = $ps_language;
$link->preloadPageLinks();
$this->canonicalRedirection();
@@ -338,14 +341,12 @@ class FrontControllerCore
if($cookie->postcode)
$customer->geoloc_postcode = (int)$cookie->postcode;
$context = Context::getContext();
$context->customer = $customer;
$context->cart = $cart;
$context->link = $link;
$context->cookie = $cookie;
$context->currency = $currency;
$context->controller = $this;
$context->language = $ps_language;
$context->country = $defaultCountry;
}
@@ -375,7 +376,7 @@ class FrontControllerCore
if (isset($this->php_self) AND !empty($this->php_self))
{
// $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain
$canonicalURL = $context->link->getPageLink($this->php_self, $this->ssl, $context->language->id_lang);
$canonicalURL = $context->link->getPageLink($this->php_self, $this->ssl, $context->language->id);
if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', (($this->ssl AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
{
header('HTTP/1.0 301 Moved');
+7 -7
View File
@@ -897,7 +897,7 @@ abstract class ModuleCore
global $_MODULES, $_MODULE;
$file = _PS_MODULE_DIR_.$this->name.'/'.$context->getContext()->language->iso_code.'.php';
$file = _PS_MODULE_DIR_.$this->name.'/'.Context::getContext()->language->iso_code.'.php';
if (Tools::file_exists_cache($file) AND include_once($file))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
@@ -1105,16 +1105,16 @@ abstract class ModuleCore
$previousTemplate = $context->smarty->currentTemplate;
$context->smarty->currentTemplate = substr(basename($template), 0, -4);
}
$context->smarty->assign('module_dir', __PS_BASE_URI__.'modules/'.basename($file, '.php').'/');
$context->controller->smarty->assign('module_dir', __PS_BASE_URI__.'modules/'.basename($file, '.php').'/');
if (($overloaded = self::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === NULL)
$result = Tools::displayError('No template found for module').' '.basename($file,'.php');
else
{
$context->smarty->assign('module_template_dir', ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/');
$result = $context->smarty->fetch(($overloaded ? _PS_THEME_DIR_.'modules/'.basename($file, '.php') : _PS_MODULE_DIR_.basename($file, '.php')).'/'.$template, $cacheId, $compileId);
$context->controller->smarty->assign('module_template_dir', ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/');
$result = $context->controller->smarty->fetch(($overloaded ? _PS_THEME_DIR_.'modules/'.basename($file, '.php') : _PS_MODULE_DIR_.basename($file, '.php')).'/'.$template, $cacheId, $compileId);
}
if (Configuration::get('PS_FORCE_SMARTY_2')) /* Keep a backward compatibility for Smarty v2 */
$context->smarty->currentTemplate = $previousTemplate;
$context->controller->smarty->currentTemplate = $previousTemplate;
return $result;
}
@@ -1129,10 +1129,10 @@ abstract class ModuleCore
/* Use Smarty 3 API calls */
if (!Configuration::get('PS_FORCE_SMARTY_2')) /* PHP version > 5.1.2 */
return $context->smarty->isCached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
return $context->controller->smarty->isCached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
/* or keep a backward compatibility if PHP version < 5.1.2 */
else
return $context->smarty->is_cached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
return $context->controller->smarty->is_cached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
}
protected function _clearCache($template, $cacheId = NULL, $compileId = NULL)
+4 -3
View File
@@ -3075,11 +3075,12 @@ class ProductCore extends ObjectModel
return Db::getInstance()->ExecuteS('SELECT `id_customization_field`, `type` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)($this->id).' AND `required` = 1');
}
public function hasAllRequiredCustomizableFields()
public function hasAllRequiredCustomizableFields($context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$fields = array_merge($cookie->getFamily('pictures_'.(int)($this->id)), $cookie->getFamily('textFields_'.(int)($this->id)));
$fields = array_merge($context->cookie->getFamily('pictures_'.(int)($this->id)), $context->cookie->getFamily('textFields_'.(int)($this->id)));
if (($requiredFields = $this->getRequiredCustomizableFields()) === false)
return false;
$prefix = array(_CUSTOMIZE_FILE_ => 'pictures_'.(int)($this->id).'_', _CUSTOMIZE_TEXTFIELD_ => 'textFields_'.(int)($this->id).'_');