// Context part 3
This commit is contained in:
@@ -614,11 +614,11 @@ class CustomerCore extends ObjectModel
|
||||
return self::$_defaultGroupId[(int)($id_customer)];
|
||||
}
|
||||
|
||||
static public function getCurrentCountry($id_customer)
|
||||
static public function getCurrentCountry($id_customer, $context = null)
|
||||
{
|
||||
global $cart;
|
||||
|
||||
if (!$cart OR !$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if (!$context->cart OR !$context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
|
||||
$id_address = (int)(Db::getInstance()->getValue('SELECT `id_address` FROM `'._DB_PREFIX_.'address` WHERE `id_customer` = '.(int)($id_customer).' AND `deleted` = 0 ORDER BY `id`'));
|
||||
else
|
||||
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
|
||||
|
||||
@@ -229,10 +229,10 @@ class DiscountCore extends ObjectModel
|
||||
* @param boolean $id_customer Customer ID
|
||||
* @return array Discounts
|
||||
*/
|
||||
static public function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false)
|
||||
static public function getCustomerDiscounts($id_lang, $id_customer, $active = false, $includeGenericOnes = true, $stock = false, $context = null)
|
||||
{
|
||||
global $cart;
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT d.*, dtl.`name` AS `type`, dl.`description`
|
||||
FROM `'._DB_PREFIX_.'discount` d
|
||||
@@ -249,7 +249,7 @@ class DiscountCore extends ObjectModel
|
||||
if ($discount['quantity_per_user'])
|
||||
{
|
||||
$quantity_used = Order::getDiscountsCustomer((int)($id_customer), (int)($discount['id_discount']));
|
||||
if (isset($cart) AND isset($cart->id))
|
||||
if (isset($context->cart) AND $context->cart->id)
|
||||
$quantity_used += $cart->getDiscountsCustomer((int)($discount['id_discount']));
|
||||
$discount['quantity_for_user'] = $discount['quantity_per_user'] - $quantity_used;
|
||||
}
|
||||
|
||||
+12
-14
@@ -102,17 +102,16 @@ class FrontControllerCore
|
||||
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
|
||||
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
|
||||
|
||||
/* Loading default country */
|
||||
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
/* Theme is missing or maintenance */
|
||||
if (!is_dir(_PS_THEME_DIR_))
|
||||
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
|
||||
elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE')))
|
||||
$this->maintenance = true;
|
||||
elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
|
||||
$defaultCountry = $this->geolocationManagement();
|
||||
|
||||
/* Loading default country */
|
||||
if (!isset($defaultCountry) && Validate::isLoadedObject($defaultCountry))
|
||||
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
if ($newDefault = $this->geolocationManagement() && Validate::isLoadedObject($newDefault))
|
||||
$defaultCountry = $newDefault;
|
||||
|
||||
// Switch language if needed and init cookie language
|
||||
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
|
||||
@@ -371,13 +370,12 @@ class FrontControllerCore
|
||||
|
||||
protected function canonicalRedirection()
|
||||
{
|
||||
global $link, $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
// Automatically redirect to the canonical URL if needed
|
||||
if (isset($this->php_self) AND !empty($this->php_self))
|
||||
{
|
||||
// $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain
|
||||
$canonicalURL = $link->getPageLink($this->php_self, $this->ssl, $cookie->id_lang);
|
||||
$canonicalURL = $context->link->getPageLink($this->php_self, $this->ssl, $context->language->id_lang);
|
||||
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');
|
||||
@@ -395,14 +393,14 @@ class FrontControllerCore
|
||||
|
||||
protected function geolocationManagement()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
|
||||
{
|
||||
/* Check if Maxmind Database exists */
|
||||
if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat'))
|
||||
{
|
||||
if (!isset($cookie->iso_code_country) OR (isset($cookie->iso_code_country) AND !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))))
|
||||
if (!isset($context->country->iso_code) OR (isset($context->country->iso_code) AND !in_array(strtoupper($context->country->iso_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))))
|
||||
{
|
||||
include_once(_PS_GEOIP_DIR_.'geoipcity.inc');
|
||||
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
|
||||
@@ -422,17 +420,17 @@ class FrontControllerCore
|
||||
}
|
||||
elseif (is_object($record))
|
||||
{
|
||||
$cookie->iso_code_country = strtoupper($record->country_code);
|
||||
$context->country->iso_code = strtoupper($record->country_code);
|
||||
$hasBeenSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($cookie->iso_code_country) AND (int)($id_country = Country::getByIso(strtoupper($cookie->iso_code_country))))
|
||||
if (isset($context->country->iso_code) AND (int)($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
|
||||
{
|
||||
/* Update defaultCountry */
|
||||
$defaultCountry = new Country($id_country);
|
||||
if (isset($hasBeenSet) AND $hasBeenSet)
|
||||
$cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
|
||||
$context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
|
||||
return $defaultCountry;
|
||||
}
|
||||
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
|
||||
|
||||
+18
-15
@@ -34,7 +34,6 @@ class LinkCore
|
||||
|
||||
public $protocol_link;
|
||||
public $protocol_content;
|
||||
public $useSSL;
|
||||
|
||||
/**
|
||||
* Constructor (initialization only)
|
||||
@@ -180,9 +179,10 @@ class LinkCore
|
||||
return Tools::getProtocol().Tools::getMediaServer($filepath).$filepath;
|
||||
}
|
||||
|
||||
public function preloadPageLinks()
|
||||
public function preloadPageLinks($context = null)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if ($this->allow != 1)
|
||||
return;
|
||||
|
||||
@@ -190,16 +190,17 @@ class LinkCore
|
||||
SELECT page, url_rewrite
|
||||
FROM `'._DB_PREFIX_.'meta` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'meta_lang` ml ON (m.id_meta = ml.id_meta)
|
||||
WHERE id_lang = '.(int)$cookie->id_lang);
|
||||
WHERE id_lang = '.(int)$context->language->id);
|
||||
foreach ($result as $row)
|
||||
self::$cache['page'][$row['page'].'.php_'.$cookie->id_lang] = $this->getLangLink((int)$cookie->id_lang).$row['url_rewrite'];
|
||||
self::$cache['page'][$row['page'].'.php_'.$context->language->id] = $this->getLangLink($context->language->id).$row['url_rewrite'];
|
||||
}
|
||||
|
||||
public function getPageLink($filename, $ssl = false, $id_lang = NULL, $request = NULL)
|
||||
public function getPageLink($filename, $ssl = false, $id_lang = NULL, $request = NULL, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if ($id_lang == NULL)
|
||||
$id_lang = (int)($cookie->id_lang);
|
||||
$id_lang = (int)$context->language->id;
|
||||
|
||||
if (array_key_exists($filename.'_'.$id_lang, self::$cache['page']) AND !empty(self::$cache['page'][$filename.'_'.$id_lang]))
|
||||
$uri_path = self::$cache['page'][$filename.'_'.$id_lang];
|
||||
@@ -244,9 +245,10 @@ class LinkCore
|
||||
* @param integer $id_lang Language ID
|
||||
* @return string link
|
||||
*/
|
||||
public function getLanguageLink($id_lang)
|
||||
public function getLanguageLink($id_lang, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$matches = array();
|
||||
$request = $_SERVER['REQUEST_URI'];
|
||||
preg_match('#^/([a-z]{2})/([^\?]*).*$#', $request, $matches);
|
||||
@@ -268,7 +270,7 @@ class LinkCore
|
||||
|
||||
$switchLangLink = $this->getPageLink(substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)), false, $id_lang).$query;
|
||||
if (!$this->allow)
|
||||
if ($id_lang != $cookie->id_lang)
|
||||
if ($id_lang != $context->language->id)
|
||||
{
|
||||
if (strpos($switchLangLink,'id_lang'))
|
||||
$switchLangLink = preg_replace('`id_lang=[0-9]*`','id_lang='.$id_lang,$switchLangLink);
|
||||
@@ -355,15 +357,16 @@ class LinkCore
|
||||
return $url.(!strstr($url, '?') ? '?' : '&').'orderby='.urlencode($orderby).'&orderway='.urlencode($orderway);
|
||||
}
|
||||
|
||||
protected function getLangLink($id_lang = NULL)
|
||||
protected function getLangLink($id_lang = NULL, $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if (!$this->allow OR Language::countActiveLanguages() <= 1)
|
||||
return '';
|
||||
|
||||
global $cookie;
|
||||
if (!$id_lang)
|
||||
$id_lang = (int)$cookie->id_lang;
|
||||
$id_lang = $context->language->id;
|
||||
|
||||
return Language::getIsoById((int)$id_lang).'/';
|
||||
return Language::getIsoById($id_lang).'/';
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -201,18 +201,19 @@ class MailCore
|
||||
*
|
||||
* @param string $string raw sentence (write directly in file)
|
||||
*/
|
||||
static public function l($string)
|
||||
static public function l($string, $context = null)
|
||||
{
|
||||
global $_LANGMAIL, $cookie;
|
||||
|
||||
global $_LANGMAIL;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$key = str_replace('\'', '\\\'', $string);
|
||||
$id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)Configuration::get('PS_LANG_DEFAULT') : (int)$cookie->id_lang;
|
||||
|
||||
$file_core = _PS_ROOT_DIR_.'/mails/'.Language::getIsoById((int)$id_lang).'/lang.php';
|
||||
$file_core = _PS_ROOT_DIR_.'/mails/'.$context->language->iso_code.'/lang.php';
|
||||
if (Tools::file_exists_cache($file_core) && empty($_LANGMAIL))
|
||||
include_once($file_core);
|
||||
|
||||
$file_theme = _PS_THEME_DIR_.'mails/'.Language::getIsoById((int)$id_lang).'/lang.php';
|
||||
$file_theme = _PS_THEME_DIR_.'mails/'.$context->language->iso_code.'/lang.php';
|
||||
if (Tools::file_exists_cache($file_theme))
|
||||
include_once($file_theme);
|
||||
|
||||
|
||||
+9
-7
@@ -98,18 +98,19 @@ class MessageCore extends ObjectModel
|
||||
* @param boolean $private return WITH private messages
|
||||
* @return array Messages
|
||||
*/
|
||||
static public function getMessagesByOrderId($id_order, $private = false)
|
||||
static public function getMessagesByOrderId($id_order, $private = false, $context = null)
|
||||
{
|
||||
if (!Validate::isBool($private))
|
||||
die(Tools::displayError());
|
||||
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$cookie->id_employee.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$context->employee->id.')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_order = '.(int)$id_order.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
@@ -124,18 +125,19 @@ class MessageCore extends ObjectModel
|
||||
* @param boolean $private return WITH private messages
|
||||
* @return array Messages
|
||||
*/
|
||||
static public function getMessagesByCartId($id_cart, $private = false)
|
||||
static public function getMessagesByCartId($id_cart, $private = false, $context = null)
|
||||
{
|
||||
if (!Validate::isBool($private))
|
||||
die(Tools::displayError());
|
||||
|
||||
global $cookie;
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$cookie->id_employee.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$context->employee->id.')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_cart = '.(int)$id_cart.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
|
||||
+26
-33
@@ -102,10 +102,8 @@ abstract class ModuleCore
|
||||
*
|
||||
* @param string $name Module unique name
|
||||
*/
|
||||
public function __construct($name = NULL)
|
||||
public function __construct($name = null)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
// Search the module shop context
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
$this->setShopID($shopID);
|
||||
@@ -491,9 +489,7 @@ abstract class ModuleCore
|
||||
if (substr(realpath($filePath), 0, strlen($realpathModuleDir)) == $realpathModuleDir)
|
||||
{
|
||||
self::$classInModule[$currentClass] = substr(dirname($filePath), strlen($realpathModuleDir)+1);
|
||||
|
||||
$id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang);
|
||||
$file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.Language::getIsoById($id_lang).'.php';
|
||||
$file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.$context->getContext()->language->iso_code.'.php';
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
}
|
||||
@@ -556,7 +552,7 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function getModulesOnDisk($useConfig = false)
|
||||
{
|
||||
global $cookie, $_MODULES;
|
||||
global $_MODULES;
|
||||
|
||||
$moduleList = array();
|
||||
$moduleListCursor = 0;
|
||||
@@ -582,7 +578,7 @@ abstract class ModuleCore
|
||||
|
||||
if (!count($errors) AND (int)$xml_module->need_instance == 0 AND !$needNewConfigFile)
|
||||
{
|
||||
$file = _PS_MODULE_DIR_.$module.'/'.Language::getIsoById($cookie->id_lang).'.php';
|
||||
$file = _PS_MODULE_DIR_.$module.'/'.$context->getContext()->language->iso_code.'.php';
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
if(isset($_MODULE) AND is_array($_MODULE))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
@@ -731,15 +727,15 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function hookExec($hook_name, $hookArgs = array(), $id_module = NULL)
|
||||
{
|
||||
global $cart, $cookie;
|
||||
$context = Context::getContext();
|
||||
if ((!empty($id_module) AND !Validate::isUnsignedId($id_module)) OR !Validate::isHookName($hook_name))
|
||||
die(Tools::displayError());
|
||||
|
||||
$live_edit = false;
|
||||
if (!isset($hookArgs['cookie']) OR !$hookArgs['cookie'])
|
||||
$hookArgs['cookie'] = $cookie;
|
||||
$hookArgs['cookie'] = $context->cookie;
|
||||
if (!isset($hookArgs['cart']) OR !$hookArgs['cart'])
|
||||
$hookArgs['cart'] = $cart;
|
||||
$hookArgs['cart'] = $context->cart;
|
||||
$hook_name = strtolower($hook_name);
|
||||
|
||||
if (!isset(self::$_hookModulesCache))
|
||||
@@ -815,17 +811,16 @@ abstract class ModuleCore
|
||||
|
||||
public static function hookExecPayment()
|
||||
{
|
||||
global $cart, $cookie;
|
||||
$hookArgs = array('cookie' => $cookie, 'cart' => $cart);
|
||||
$id_customer = (int)($cookie->id_customer);
|
||||
$billing = new Address((int)($cart->id_address_invoice));
|
||||
$context = Context::getContext();
|
||||
$hookArgs = array('cookie' => $context->cookie, 'cart' => $context->cart);
|
||||
$billing = new Address((int)($context->cart->id_address_invoice));
|
||||
$output = '';
|
||||
$list = Shop::getListFromContext();
|
||||
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module_country` mc
|
||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
|
||||
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group` AND cg.`id_customer` = '.(int)($id_customer).')
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group` AND cg.`id_customer` = '.(int)$context->customer->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \'payment\'
|
||||
@@ -900,10 +895,9 @@ abstract class ModuleCore
|
||||
if (self::$_generateConfigXmlMode)
|
||||
return $string;
|
||||
|
||||
global $_MODULES, $_MODULE, $cookie;
|
||||
global $_MODULES, $_MODULE;
|
||||
|
||||
$id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang);
|
||||
$file = _PS_MODULE_DIR_.$this->name.'/'.Language::getIsoById($id_lang).'.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;
|
||||
|
||||
@@ -1104,23 +1098,23 @@ abstract class ModuleCore
|
||||
|
||||
public static function display($file, $template, $cacheId = NULL, $compileId = NULL)
|
||||
{
|
||||
global $smarty;
|
||||
$context = Context::getContext();
|
||||
|
||||
if (Configuration::get('PS_FORCE_SMARTY_2')) /* Keep a backward compatibility for Smarty v2 */
|
||||
{
|
||||
$previousTemplate = $smarty->currentTemplate;
|
||||
$smarty->currentTemplate = substr(basename($template), 0, -4);
|
||||
$previousTemplate = $context->smarty->currentTemplate;
|
||||
$context->smarty->currentTemplate = substr(basename($template), 0, -4);
|
||||
}
|
||||
$smarty->assign('module_dir', __PS_BASE_URI__.'modules/'.basename($file, '.php').'/');
|
||||
$context->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
|
||||
{
|
||||
$smarty->assign('module_template_dir', ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/');
|
||||
$result = $smarty->fetch(($overloaded ? _PS_THEME_DIR_.'modules/'.basename($file, '.php') : _PS_MODULE_DIR_.basename($file, '.php')).'/'.$template, $cacheId, $compileId);
|
||||
$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);
|
||||
}
|
||||
if (Configuration::get('PS_FORCE_SMARTY_2')) /* Keep a backward compatibility for Smarty v2 */
|
||||
$smarty->currentTemplate = $previousTemplate;
|
||||
$context->smarty->currentTemplate = $previousTemplate;
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -1131,26 +1125,25 @@ abstract class ModuleCore
|
||||
|
||||
public function isCached($template, $cacheId = NULL, $compileId = NULL)
|
||||
{
|
||||
global $smarty;
|
||||
$context = Context::getContext();
|
||||
|
||||
/* Use Smarty 3 API calls */
|
||||
if (!Configuration::get('PS_FORCE_SMARTY_2')) /* PHP version > 5.1.2 */
|
||||
return $smarty->isCached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
|
||||
return $context->smarty->isCached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
|
||||
/* or keep a backward compatibility if PHP version < 5.1.2 */
|
||||
else
|
||||
return $smarty->is_cached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
|
||||
return $context->smarty->is_cached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
|
||||
}
|
||||
|
||||
protected function _clearCache($template, $cacheId = NULL, $compileId = NULL)
|
||||
{
|
||||
global $smarty;
|
||||
|
||||
$context = Context::getContext();
|
||||
/* Use Smarty 3 API calls */
|
||||
if (!Configuration::get('PS_FORCE_SMARTY_2')) /* PHP version > 5.1.2 */
|
||||
return $smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
return $context->smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
/* or keep a backward compatibility if PHP version < 5.1.2 */
|
||||
else
|
||||
return $smarty->clear_cache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
return $context->smarty->clear_cache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
}
|
||||
|
||||
protected function _generateConfigXml()
|
||||
|
||||
+8
-13
@@ -159,10 +159,10 @@ abstract class ModuleGraphCore extends Module
|
||||
|
||||
protected function csvExport($datas)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$this->setEmployee(intval($cookie->id_employee));
|
||||
$this->setLang(intval($cookie->id_lang));
|
||||
$context = Context::getContext();
|
||||
|
||||
$this->setEmployee($context->employee->id);
|
||||
$this->setLang($context->language->id);
|
||||
|
||||
$layers = isset($datas['layers']) ? $datas['layers'] : 1;
|
||||
if (isset($datas['option']))
|
||||
@@ -257,16 +257,14 @@ abstract class ModuleGraphCore extends Module
|
||||
|
||||
public function engine($params)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
if (!($render = Configuration::get('PS_STATS_RENDER')))
|
||||
return Tools::displayError('No graph engine selected');
|
||||
if (!file_exists(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
|
||||
return Tools::displayError('Graph engine selected is unavailable.');
|
||||
|
||||
global $cookie;
|
||||
$id_employee = (int)($cookie->id_employee);
|
||||
$id_lang = (int)($cookie->id_lang);
|
||||
$id_employee = (int)($context->employee->id);
|
||||
$id_lang = (int)($context->language->id);
|
||||
|
||||
if (!isset($params['layers']))
|
||||
$params['layers'] = 1;
|
||||
@@ -291,10 +289,7 @@ abstract class ModuleGraphCore extends Module
|
||||
protected static function getEmployee($employee = null)
|
||||
{
|
||||
if (!$employee)
|
||||
{
|
||||
global $cookie;
|
||||
$employee = new Employee((int)($cookie->id_employee));
|
||||
}
|
||||
$employee = $context->employee;
|
||||
|
||||
if (empty($employee->stats_date_from) OR empty($employee->stats_date_to) OR $employee->stats_date_from == '0000-00-00' OR $employee->stats_date_to == '0000-00-00')
|
||||
{
|
||||
|
||||
@@ -102,9 +102,9 @@ abstract class ModuleGridCore extends Module
|
||||
|
||||
$grider = 'grider.php?render='.$render.'&module='.Tools::getValue('module');
|
||||
|
||||
global $cookie;
|
||||
$grider .= '&id_employee='.(int)($cookie->id_employee);
|
||||
$grider .= '&id_lang='.(int)($cookie->id_lang);
|
||||
$context = Context::getContext();
|
||||
$grider .= '&id_employee='.(int)($context->employee->id);
|
||||
$grider .= '&id_lang='.(int)($context->language->id);
|
||||
|
||||
if (!isset($params['width']) OR !Validate::IsUnsignedInt($params['width']))
|
||||
$params['width'] = 600;
|
||||
@@ -136,9 +136,8 @@ abstract class ModuleGridCore extends Module
|
||||
|
||||
protected function csvExport($datas)
|
||||
{
|
||||
global $cookie;
|
||||
$this->_sort = $datas['defaultSortColumn'];
|
||||
$this->setLang($cookie->id_lang);
|
||||
$this->setLang(Context::getContext()->language->id);
|
||||
$this->getData();
|
||||
|
||||
$layers = isset($datas['layers']) ? $datas['layers'] : 1;
|
||||
|
||||
@@ -487,11 +487,10 @@ abstract class ObjectModelCore
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function displayFieldName($field, $className = __CLASS__, $htmlentities = true)
|
||||
static public function displayFieldName($field, $className = __CLASS__, $htmlentities = true, $context = null)
|
||||
{
|
||||
global $_FIELDS, $cookie;
|
||||
$iso = strtolower(Language::getIsoById($cookie->id_lang ? (int)$cookie->id_lang : Configuration::get('PS_LANG_DEFAULT')));
|
||||
@include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php');
|
||||
global $_FIELDS;
|
||||
@include(_PS_TRANSLATIONS_DIR_.Context::getContext()->language->iso_code.'/fields.php');
|
||||
|
||||
$key = $className.'_'.md5($field);
|
||||
return ((is_array($_FIELDS) AND array_key_exists($key, $_FIELDS)) ? ($htmlentities ? htmlentities($_FIELDS[$key], ENT_QUOTES, 'utf-8') : $_FIELDS[$key]) : $field);
|
||||
|
||||
+9
-8
@@ -329,7 +329,6 @@ class OrderCore extends ObjectModel
|
||||
return false;
|
||||
if (count($this->getProductsDetail()) == 0)
|
||||
{
|
||||
global $cookie;
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int)($this->id);
|
||||
$history->changeIdOrderState(_PS_OS_CANCELED_, (int)($this->id));
|
||||
@@ -627,10 +626,11 @@ class OrderCore extends ObjectModel
|
||||
* @param boolean $showHiddenStatus Display or not hidden order statuses
|
||||
* @return array Customer orders
|
||||
*/
|
||||
static public function getCustomerOrders($id_customer, $showHiddenStatus = false)
|
||||
static public function getCustomerOrders($id_customer, $showHiddenStatus = false, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT o.*, (SELECT SUM(od.`product_quantity`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = o.`id_order`) nb_products
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
@@ -646,7 +646,7 @@ class OrderCore extends ObjectModel
|
||||
SELECT os.`id_order_state`, osl.`name` AS order_state, os.`invoice`
|
||||
FROM `'._DB_PREFIX_.'order_history` oh
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
|
||||
INNER JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')
|
||||
INNER JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$context->language->id.')
|
||||
WHERE oh.`id_order` = '.(int)($val['id_order']).(!$showHiddenStatus ? ' AND os.`hidden` != 1' : '').'
|
||||
ORDER BY oh.`date_add` DESC, oh.`id_order_history` DESC
|
||||
LIMIT 1');
|
||||
@@ -685,16 +685,17 @@ class OrderCore extends ObjectModel
|
||||
'.((int)$limit ? 'LIMIT 0, '.(int)$limit : ''));
|
||||
}
|
||||
|
||||
static public function getOrdersWithInformations($limit = NULL)
|
||||
static public function getOrdersWithInformations($limit = NULL, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = 'SELECT *, (
|
||||
SELECT `name`
|
||||
FROM `'._DB_PREFIX_.'order_history` oh
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (osl.`id_order_state` = oh.`id_order_state`)
|
||||
WHERE oh.`id_order` = o.`id_order`
|
||||
AND osl.`id_lang` = '.(int)$cookie->id_lang.'
|
||||
AND osl.`id_lang` = '.(int)$context->language->id.'
|
||||
ORDER BY oh.`date_add` DESC
|
||||
LIMIT 1
|
||||
) AS `state_name`
|
||||
|
||||
@@ -127,8 +127,10 @@ class OrderHistoryCore extends ObjectModel
|
||||
return new OrderState($id_order_state, Configuration::get('PS_LANG_DEFAULT'));
|
||||
}
|
||||
|
||||
public function addWithemail($autodate = true, $templateVars = false)
|
||||
public function addWithemail($autodate = true, $templateVars = false, $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$lastOrderState = $this->getLastOrderState($this->id_order);
|
||||
|
||||
if (!parent::add($autodate))
|
||||
@@ -157,7 +159,6 @@ class OrderHistoryCore extends ObjectModel
|
||||
// An additional email is sent the first time a virtual item is validated
|
||||
if ($virtualProducts = $order->getVirtualProducts() AND (!$lastOrderState OR !$lastOrderState->logable) AND $newOrderState = new OrderState($this->id_order_state, Configuration::get('PS_LANG_DEFAULT')) AND $newOrderState->logable)
|
||||
{
|
||||
global $smarty;
|
||||
$assign = array();
|
||||
foreach ($virtualProducts AS $key => $virtualProduct)
|
||||
{
|
||||
@@ -173,10 +174,10 @@ class OrderHistoryCore extends ObjectModel
|
||||
if ($product_download->nb_downloadable != 0)
|
||||
$assign[$key]['downloadable'] = $product_download->nb_downloadable;
|
||||
}
|
||||
$smarty->assign('virtualProducts', $assign);
|
||||
$smarty->assign('id_order', $order->id);
|
||||
$context->smarty->assign('virtualProducts', $assign);
|
||||
$context->smarty->assign('id_order', $order->id);
|
||||
$iso = Language::getIsoById((int)($order->id_lang));
|
||||
$links = $smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
|
||||
$links = $context->smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
|
||||
$tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
|
||||
$data = array_merge ($data, $tmpArray);
|
||||
global $_LANGMAIL;
|
||||
|
||||
@@ -132,10 +132,10 @@ class OrderReturnCore extends ObjectModel
|
||||
return (int)($data['total']);
|
||||
}
|
||||
|
||||
static public function getOrdersReturn($customer_id, $order_id = false, $no_denied = false)
|
||||
static public function getOrdersReturn($customer_id, $order_id = false, $no_denied = false, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$data = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_return`
|
||||
@@ -146,7 +146,7 @@ class OrderReturnCore extends ObjectModel
|
||||
foreach ($data AS $k => $or)
|
||||
{
|
||||
$state = new OrderReturnState($or['state']);
|
||||
$data[$k]['state_name'] = $state->name[$cookie->id_lang];
|
||||
$data[$k]['state_name'] = $state->name[$context->language->id];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
+11
-16
@@ -104,11 +104,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
*/
|
||||
public function __construct($orientation='P', $unit='mm', $format='A4')
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if (!isset($cookie) OR !is_object($cookie))
|
||||
$cookie->id_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||
self::$_iso = strtoupper(Language::getIsoById($cookie->id_lang));
|
||||
self::$_iso = strtoupper(Context::getContext()->language->iso_code);
|
||||
FPDF::FPDF($orientation, $unit, $format);
|
||||
$this->_initPDFFonts();
|
||||
}
|
||||
@@ -139,8 +135,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
*/
|
||||
public function Header()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
$conf = Configuration::getMultiple(array('PS_SHOP_NAME', 'PS_SHOP_ADDR1', 'PS_SHOP_CODE', 'PS_SHOP_CITY', 'PS_SHOP_COUNTRY', 'PS_SHOP_STATE'));
|
||||
$conf['PS_SHOP_NAME'] = isset($conf['PS_SHOP_NAME']) ? Tools::iconv('utf-8', self::encoding(), $conf['PS_SHOP_NAME']) : 'Your company';
|
||||
$conf['PS_SHOP_ADDR1'] = isset($conf['PS_SHOP_ADDR1']) ? Tools::iconv('utf-8', self::encoding(), $conf['PS_SHOP_ADDR1']) : 'Your company';
|
||||
@@ -161,9 +156,9 @@ class PDFCore extends PDF_PageGroupCore
|
||||
elseif (self::$orderSlip)
|
||||
$this->Cell(77, 10, self::l('SLIP #').' '.sprintf('%06d', self::$orderSlip->id), 0, 1, 'R');
|
||||
elseif (self::$delivery)
|
||||
$this->Cell(77, 10, self::l('DELIVERY SLIP #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$delivery), 0, 1, 'R');
|
||||
$this->Cell(77, 10, self::l('DELIVERY SLIP #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', $context->language->id)).sprintf('%06d', self::$delivery), 0, 1, 'R');
|
||||
elseif (self::$order->invoice_number)
|
||||
$this->Cell(77, 10, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$order->invoice_number), 0, 1, 'R');
|
||||
$this->Cell(77, 10, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', $context->language->id)).sprintf('%06d', self::$order->invoice_number), 0, 1, 'R');
|
||||
else
|
||||
$this->Cell(77, 10, self::l('ORDER #').' '.sprintf('%06d', self::$order->id), 0, 1, 'R');
|
||||
}
|
||||
@@ -481,11 +476,12 @@ class PDFCore extends PDF_PageGroupCore
|
||||
* @param object $order Order
|
||||
* @param string $mode Download or display (optional)
|
||||
*/
|
||||
public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false)
|
||||
public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false, $context = null)
|
||||
{
|
||||
global $cookie;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!Validate::isLoadedObject($order) OR (!$cookie->id_employee AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
|
||||
if (!Validate::isLoadedObject($order) OR (!$context->employee->id AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
|
||||
die('Invalid order or invalid order state');
|
||||
self::$order = $order;
|
||||
self::$orderSlip = $slip;
|
||||
@@ -560,9 +556,9 @@ class PDFCore extends PDF_PageGroupCore
|
||||
if (self::$orderSlip)
|
||||
$pdf->Cell(0, 6, self::l('SLIP #').' '.sprintf('%06d', self::$orderSlip->id).' '.self::l('from') . ' ' .Tools::displayDate(self::$orderSlip->date_upd, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
elseif (self::$delivery)
|
||||
$pdf->Cell(0, 6, self::l('DELIVERY SLIP #').Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$delivery).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
$pdf->Cell(0, 6, self::l('DELIVERY SLIP #').Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', $context->language->id)).sprintf('%06d', self::$delivery).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
else
|
||||
$pdf->Cell(0, 6, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
$pdf->Cell(0, 6, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', $context->language->id)).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
$pdf->Cell(55, 6, self::l('Order #').' '.sprintf('%06d', self::$order->id), 'L', 0);
|
||||
$pdf->Cell(70, 6, self::l('Carrier:').($order->gift ? ' '.Tools::iconv('utf-8', self::encoding(), $carrier->name) : ''), 'L');
|
||||
$pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
|
||||
@@ -1092,8 +1088,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
|
||||
static protected function l($string)
|
||||
{
|
||||
global $cookie;
|
||||
$iso = Language::getIsoById((isset($cookie->id_lang) AND Validate::isUnsignedId($cookie->id_lang)) ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'));
|
||||
$iso = Context::getContext()->language->iso_code;
|
||||
|
||||
if (@!include(_PS_TRANSLATIONS_DIR_.$iso.'/pdf.php'))
|
||||
die('Cannot include PDF translation language file : '._PS_TRANSLATIONS_DIR_.$iso.'/pdf.php');
|
||||
|
||||
@@ -53,10 +53,7 @@ class PackCore extends Product
|
||||
|
||||
public static function noPackPrice($id_product)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$sum = 0;
|
||||
|
||||
$price_display_method = !self::$_taxCalculationMethod;
|
||||
$items = self::getItems($id_product, Configuration::get('PS_LANG_DEFAULT'));
|
||||
foreach ($items as $item)
|
||||
|
||||
@@ -90,8 +90,6 @@ abstract class PaymentModuleCore extends Module
|
||||
*/
|
||||
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false, $secure_key = false, $id_group_shop = false, $id_shop = false)
|
||||
{
|
||||
global $cart;
|
||||
|
||||
$cart = new Cart((int)($id_cart));
|
||||
// Does order already exists ?
|
||||
if (Validate::isLoadedObject($cart) AND $cart->OrderExists() == false)
|
||||
@@ -501,7 +499,7 @@ abstract class PaymentModuleCore extends Module
|
||||
public function getCurrency($current_id_currency = NULL)
|
||||
{
|
||||
if (!(int)$current_id_currency)
|
||||
global $cookie;
|
||||
$current_id_currency = Context::getContext()->currency->id;
|
||||
|
||||
if (!$this->currencies)
|
||||
return false;
|
||||
@@ -515,13 +513,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$currencies = Currency::getPaymentCurrenciesSpecial($this->id);
|
||||
$currency = $currencies['id_currency'];
|
||||
if ($currency == -1)
|
||||
{
|
||||
// not use $cookie if $current_id_currency is set
|
||||
if ((int)$current_id_currency)
|
||||
$id_currency = (int)$current_id_currency;
|
||||
else
|
||||
$id_currency = (int)($cookie->id_currency);
|
||||
}
|
||||
$id_currency = (int)$current_id_currency;
|
||||
elseif ($currency == -2)
|
||||
$id_currency = (int)(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user