// Context part 8

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7633 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean committed 2011-07-15 16:41:39 +00:00
1 parent 20276404a8
commit 311e8ab964
10 files changed
+158 -156

No files matched your search

+7 -7
View File
@@ -100,7 +100,7 @@ class FrontControllerCore
ob_start(); ob_start();
$cookie = new Cookie('ps'); $cookie = new Cookie('ps');
$context->cookie = $cookie;
if ($this->auth AND !$cookie->isLogged($this->guestAllowed)) if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : '')); Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
@@ -110,7 +110,7 @@ class FrontControllerCore
elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE'))) elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE')))
$this->maintenance = true; $this->maintenance = true;
elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
if ($newDefault = $this->geolocationManagement() && Validate::isLoadedObject($newDefault)) if (($newDefault = $this->geolocationManagement($defaultCountry)) && Validate::isLoadedObject($newDefault))
$defaultCountry = $newDefault; $defaultCountry = $newDefault;
// Switch language if needed and init cookie language // Switch language if needed and init cookie language
@@ -388,7 +388,7 @@ class FrontControllerCore
} }
} }
protected function geolocationManagement() protected function geolocationManagement($defaultCountry)
{ {
$context = Context::getContext(); $context = Context::getContext();
@@ -403,7 +403,7 @@ class FrontControllerCore
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php'); include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
$gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD); $gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, Tools::getRemoteAddr()); $record = geoip_record_by_addr($gi, '81.57.72.226');//Tools::getRemoteAddr());
if (is_object($record)) if (is_object($record))
{ {
@@ -425,11 +425,11 @@ class FrontControllerCore
} }
} }
if (isset($context->cookie->iso_code_country) if (isset($context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
&& (int)($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
{ {
/* Update defaultCountry */ /* Update defaultCountry */
$defaultCountry = new Country($id_country); if($defaultCountry->iso_code != $context->cookie->iso_code_country)
$defaultCountry = new Country($id_country);
if (isset($hasBeenSet) AND $hasBeenSet) if (isset($hasBeenSet) AND $hasBeenSet)
$context->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; return $defaultCountry;
+1 -2
View File
@@ -208,7 +208,6 @@ class SceneCore extends ObjectModel
*/ */
public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, $context = null) public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, $context = null)
{ {
global $link;
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang; $id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
@@ -223,7 +222,7 @@ class SceneCore extends ObjectModel
foreach ($products AS &$product) foreach ($products AS &$product)
{ {
$product['details'] = new Product($product['id_product'], !$liteResult, $id_lang); $product['details'] = new Product($product['id_product'], !$liteResult, $id_lang);
$product['link'] = $link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13); $product['link'] = $context->link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13);
$cover = Product::getCover($product['details']->id); $cover = Product::getCover($product['details']->id);
if(is_array($cover)) if(is_array($cover))
$product = array_merge($cover, $product); $product = array_merge($cover, $product);
-2
View File
@@ -113,8 +113,6 @@ class SupplierCore extends ObjectModel
*/ */
static public function getSuppliers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false) static public function getSuppliers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
{ {
global $cookie;
if (!$id_lang) if (!$id_lang)
$id_lang = Configuration::get('PS_LANG_DEFAULT'); $id_lang = Configuration::get('PS_LANG_DEFAULT');
$query = 'SELECT s.*, sl.`description`'; $query = 'SELECT s.*, sl.`description`';
+5 -5
View File
@@ -78,11 +78,11 @@ class TabCore extends ObjectModel
return false; return false;
} }
static public function initAccess($id_tab) static public function initAccess($id_tab, $context = null)
{ {
/* Cookie's loading */ if (!$context)
global $cookie; $context = Context::getContext();
if (!is_object($cookie) OR !$cookie->profile) if (!$context->employee->id_profile)
return false; return false;
/* Profile selection */ /* Profile selection */
$profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile'); $profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile');
@@ -92,7 +92,7 @@ class TabCore extends ObjectModel
$query = 'INSERT INTO `'._DB_PREFIX_.'access` VALUES '; $query = 'INSERT INTO `'._DB_PREFIX_.'access` VALUES ';
foreach ($profiles AS $profile) foreach ($profiles AS $profile)
{ {
$rights = (((int)($profile['id_profile']) == 1 OR (int)($profile['id_profile']) == $cookie->profile) ? 1 : 0); $rights = (((int)($profile['id_profile']) == 1 OR (int)($profile['id_profile']) == $context->employee->id_profile) ? 1 : 0);
$query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)($profile['id_profile']).', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')'; $query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)($profile['id_profile']).', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')';
} }
return Db::getInstance()->Execute($query); return Db::getInstance()->Execute($query);
+4 -3
View File
@@ -161,10 +161,11 @@ class TagCore extends ObjectModel
return $result; return $result;
} }
public function getProducts($associated = true) public function getProducts($associated = true, $context = null)
{ {
global $cookie; if (!$context)
$id_lang = $this->id_lang ? $this->id_lang : $cookie->id_lang; $context = Context::getContext();
$id_lang = $this->id_lang ? $this->id_lang : $context->language->id;
if (!$this->id AND $associated) if (!$this->id AND $associated)
return array(); return array();
-2
View File
@@ -231,8 +231,6 @@ class TaxCore extends ObjectModel
public static function getApplicableTaxRate($id_tax, $productTax, $id_address = NULL) public static function getApplicableTaxRate($id_tax, $productTax, $id_address = NULL)
{ {
Tools::displayAsDeprecated(); Tools::displayAsDeprecated();
global $cart, $cookie, $defaultCountry;
return $productTax; return $productTax;
} }
+42 -41
View File
@@ -55,11 +55,10 @@ class ToolsCore
* @param string $url Desired URL * @param string $url Desired URL
* @param string $baseUri Base URI (optional) * @param string $baseUri Base URI (optional)
*/ */
public static function redirect($url, $baseUri = __PS_BASE_URI__) public static function redirect($url, $baseUri = __PS_BASE_URI__, $context = null)
{ {
if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE) if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE)
{ {
global $link;
if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0) if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0)
$url = substr($url, strlen($baseUri)); $url = substr($url, strlen($baseUri));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0) { if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0) {
@@ -69,7 +68,7 @@ class ToolsCore
} }
$explode = explode('?', $url); $explode = explode('?', $url);
$url = $link->getPageLink($explode[0], true); $url = $context->link->getPageLink($explode[0], true);
if (isset($explode[1])) if (isset($explode[1]))
$url .= '?'.$explode[1]; $url .= '?'.$explode[1];
$baseUri = ''; $baseUri = '';
@@ -91,17 +90,15 @@ class ToolsCore
{ {
if (!preg_match('@^https?://@i', $url)) if (!preg_match('@^https?://@i', $url))
{ {
global $link;
if (strpos($url, __PS_BASE_URI__) !== FALSE && strpos($url, __PS_BASE_URI__) == 0) if (strpos($url, __PS_BASE_URI__) !== FALSE && strpos($url, __PS_BASE_URI__) == 0)
$url = substr($url, strlen(__PS_BASE_URI__)); $url = substr($url, strlen(__PS_BASE_URI__));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0) if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0)
$url = substr($url, strlen('index.php?controller=')); $url = substr($url, strlen('index.php?controller='));
$explode = explode('?', $url); $explode = explode('?', $url);
$url = $link->getPageLink($explode[0]); $url = $context->link->getPageLink($explode[0]);
if (isset($explode[1])) if (isset($explode[1]))
$url .= '?'.$explode[1]; $url .= '?'.$explode[1];
} }
header('Location: '.$url); header('Location: '.$url);
exit; exit;
} }
@@ -528,12 +525,11 @@ class ToolsCore
* *
* @param integer $code Error code * @param integer $code Error code
*/ */
public static function displayError($string = 'Fatal error', $htmlentities = true) public static function displayError($string = 'Fatal error', $htmlentities = true, $context = null)
{ {
global $_ERRORS, $cookie; global $_ERRORS;
$iso = strtolower(Language::getIsoById((is_object($cookie) AND $cookie->id_lang) ? (int)$cookie->id_lang : (int)Configuration::get('PS_LANG_DEFAULT'))); @include_once(_PS_TRANSLATIONS_DIR_.$context->language->iso_code.'/errors.php');
@include_once(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $string == 'Fatal error') if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $string == 'Fatal error')
return ('<pre>'.print_r(debug_backtrace(), true).'</pre>'); return ('<pre>'.print_r(debug_backtrace(), true).'</pre>');
@@ -715,8 +711,6 @@ class ToolsCore
*/ */
public static function getHomeMetaTags($id_lang, $page_name) public static function getHomeMetaTags($id_lang, $page_name)
{ {
global $cookie;
/* Metas-tags */ /* Metas-tags */
$metas = Meta::getMetaByPage($page_name, $id_lang); $metas = Meta::getMetaByPage($page_name, $id_lang);
$ret['meta_title'] = (isset($metas['title']) AND $metas['title']) ? $metas['title'].' - '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME'); $ret['meta_title'] = (isset($metas['title']) AND $metas['title']) ? $metas['title'].' - '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME');
@@ -726,16 +720,17 @@ class ToolsCore
} }
public static function completeMetaTags($metaTags, $defaultValue) public static function completeMetaTags($metaTags, $defaultValue, $context = null)
{ {
global $cookie; if (!$context)
$context = Context::getContext();
if ($metaTags['meta_title'] == NULL) if ($metaTags['meta_title'] == NULL)
$metaTags['meta_title'] = $defaultValue.' - '.Configuration::get('PS_SHOP_NAME'); $metaTags['meta_title'] = $defaultValue.' - '.Configuration::get('PS_SHOP_NAME');
if ($metaTags['meta_description'] == NULL) if ($metaTags['meta_description'] == NULL)
$metaTags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', (int)($cookie->id_lang)) ? Configuration::get('PS_META_DESCRIPTION', (int)($cookie->id_lang)) : ''; $metaTags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', $context->language->id) ? Configuration::get('PS_META_DESCRIPTION', $context->language->id) : '';
if ($metaTags['meta_keywords'] == NULL) if ($metaTags['meta_keywords'] == NULL)
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', (int)($cookie->id_lang)) ? Configuration::get('PS_META_KEYWORDS', (int)($cookie->id_lang)) : ''; $metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', $context->language->id) ? Configuration::get('PS_META_KEYWORDS', $context->language->id) : '';
return $metaTags; return $metaTags;
} }
@@ -754,13 +749,14 @@ class ToolsCore
* *
* @param string $token token to encrypt * @param string $token token to encrypt
*/ */
public static function getToken($page = true) public static function getToken($page = true, $context = null)
{ {
global $cookie; if (!$context)
$context = Context::getContext();
if ($page === true) if ($page === true)
return (self::encrypt($cookie->id_customer.$cookie->passwd.$_SERVER['SCRIPT_NAME'])); return (self::encrypt($context->customer->id.$context->customer->passwd.$_SERVER['SCRIPT_NAME']));
else else
return (self::encrypt($cookie->id_customer.$cookie->passwd.$page)); return (self::encrypt($context->customer->id.$context->customer->passwd.$page));
} }
/** /**
@@ -772,10 +768,11 @@ class ToolsCore
{ {
return !empty($string) ? self::encrypt($string) : false; return !empty($string) ? self::encrypt($string) : false;
} }
public static function getAdminTokenLite($tab) public static function getAdminTokenLite($tab, $context = null)
{ {
global $cookie; if (!$context)
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$cookie->id_employee); $context = Context::getContext();
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$context->employee->id);
} }
/** /**
@@ -786,9 +783,10 @@ class ToolsCore
* @param boolean $linkOntheLastItem Put or not a link on the current category * @param boolean $linkOntheLastItem Put or not a link on the current category
* @param string [optionnal] $categoryType defined what type of categories is used (products or cms) * @param string [optionnal] $categoryType defined what type of categories is used (products or cms)
*/ */
public static function getPath($id_category, $path = '', $linkOntheLastItem = false, $categoryType = 'products') public static function getPath($id_category, $path = '', $linkOntheLastItem = false, $categoryType = 'products', $context = null)
{ {
global $link, $cookie; if (!$context)
$context = Context::getContext();
if ($id_category == 1) if ($id_category == 1)
return '<span class="navigation_end">'.$path.'</span>'; return '<span class="navigation_end">'.$path.'</span>';
@@ -812,7 +810,7 @@ class ToolsCore
SELECT c.id_category, cl.name, cl.link_rewrite SELECT c.id_category, cl.name, cl.link_rewrite
FROM '._DB_PREFIX_.'category c FROM '._DB_PREFIX_.'category c
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category) LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category)
WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)($cookie->id_lang).' AND c.id_category != 1 WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)$context->language->id.' AND c.id_category != 1
ORDER BY c.level_depth ASC ORDER BY c.level_depth ASC
LIMIT '.(int)$category['level_depth']); LIMIT '.(int)$category['level_depth']);
@@ -821,7 +819,7 @@ class ToolsCore
foreach ($categories AS $category) foreach ($categories AS $category)
{ {
$fullPath .= $fullPath .=
(($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : ''). (($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8'). htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
(($n < $nCategories OR $linkOntheLastItem) ? '</a>' : ''). (($n < $nCategories OR $linkOntheLastItem) ? '</a>' : '').
(($n++ != $nCategories OR !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : ''); (($n++ != $nCategories OR !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');
@@ -832,10 +830,10 @@ class ToolsCore
} }
elseif ($categoryType === 'CMS') elseif ($categoryType === 'CMS')
{ {
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang)); $category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category)) if (!Validate::isLoadedObject($category))
die(self::displayError()); die(self::displayError());
$categoryLink = $link->getCMSCategoryLink($category); $categoryLink = $context->link->getCMSCategoryLink($category);
if ($path != $category->name) if ($path != $category->name)
$fullPath .= '<a href="'.self::safeOutput($categoryLink).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path; $fullPath .= '<a href="'.self::safeOutput($categoryLink).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
@@ -849,16 +847,17 @@ class ToolsCore
/** /**
* @param string [optionnal] $type_cat defined what type of categories is used (products or cms) * @param string [optionnal] $type_cat defined what type of categories is used (products or cms)
*/ */
public static function getFullPath($id_category, $end, $type_cat = 'products') public static function getFullPath($id_category, $end, $type_cat = 'products', $context = null)
{ {
global $cookie; if (!$context)
$context = Context::getContext();
$pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'); $pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
if($type_cat === 'products') if($type_cat === 'products')
$category = new Category((int)($id_category), (int)($cookie->id_lang)); $category = new Category($id_category, $context->language->id);
else if ($type_cat === 'CMS') else if ($type_cat === 'CMS')
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang)); $category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category)) if (!Validate::isLoadedObject($category))
$id_category = 1; $id_category = 1;
@@ -914,11 +913,10 @@ class ToolsCore
*/ */
public static function historyc_l($key, $translations) public static function historyc_l($key, $translations)
{ {
global $cookie;
if (!$translations OR !is_array($translations)) if (!$translations OR !is_array($translations))
die(self::displayError()); die(self::displayError());
$iso = strtoupper(Language::getIsoById($cookie->id_lang)); $iso = strtoupper(Language::getIsoById($cookie->id_lang));
$lang = key_exists($iso, $translations) ? $translations[$iso] : false; $lang = key_exists($context->language->iso_code, $translations) ? $translations[$context->language->iso_code] : false;
return (($lang AND is_array($lang) AND key_exists($key, $lang)) ? stripslashes($lang[$key]) : $key); return (($lang AND is_array($lang) AND key_exists($key, $lang)) ? stripslashes($lang[$key]) : $key);
} }
@@ -1375,7 +1373,7 @@ class ToolsCore
public static function replaceByAbsoluteURL($matches) public static function replaceByAbsoluteURL($matches)
{ {
global $current_css_file, $protocol_link; global $current_css_file;
$protocolLink = Tools::getCurrentUrlProtocolPrefix(); $protocolLink = Tools::getCurrentUrlProtocolPrefix();
@@ -1857,10 +1855,11 @@ FileETag INode MTime Size
} }
} }
public static function enableCache($level = 1) public static function enableCache($level = 1, $context = null)
{ {
global $smarty; if (!$context)
$context = Context::getContext();
$smarty = $context->controller->smarty;
if (!Configuration::get('PS_SMARTY_CACHE')) if (!Configuration::get('PS_SMARTY_CACHE'))
return; return;
if ($smarty->force_compile == 0 AND $smarty->caching == $level) if ($smarty->force_compile == 0 AND $smarty->caching == $level)
@@ -1871,9 +1870,11 @@ FileETag INode MTime Size
$smarty->caching = (int)($level); $smarty->caching = (int)($level);
} }
public static function restoreCacheSettings() public static function restoreCacheSettings($context = null)
{ {
global $smarty; if (!$context)
$context = Context::getContext();
$smarty = $context->controller->smarty;
if (isset(self::$_forceCompile)) if (isset(self::$_forceCompile))
$smarty->force_compile = (int)(self::$_forceCompile); $smarty->force_compile = (int)(self::$_forceCompile);
+5 -5
View File
@@ -141,15 +141,15 @@ class OrderControllerCore extends ParentOrderController
public function displayContent() public function displayContent()
{ {
global $currency; $context = Context::getContext();
parent::displayContent(); parent::displayContent();
$this->smarty->assign(array( $this->smarty->assign(array(
'currencySign' => $currency->sign, 'currencySign' => $context->currency->sign,
'currencyRate' => $currency->conversion_rate, 'currencyRate' => $context->currency->conversion_rate,
'currencyFormat' => $currency->format, 'currencyFormat' => $context->currency->format,
'currencyBlank' => $currency->blank, 'currencyBlank' => $context->currency->blank,
)); ));
switch ((int)$this->step) switch ((int)$this->step)
+85 -79
View File
@@ -45,13 +45,14 @@ class ParentOrderControllerCore extends FrontController
public function init() public function init()
{ {
parent::init(); parent::init();
$this->nbProducts = self::$cart->nbProducts(); $context = Context::getContext();
$this->nbProducts = $context->cart->nbProducts();
} }
public function preProcess() public function preProcess()
{ {
global $isVirtualCart; global $isVirtualCart;
$context = Context::getContext();
parent::preProcess(); parent::preProcess();
// Redirect to the good order process // Redirect to the good order process
@@ -69,7 +70,7 @@ class ParentOrderControllerCore extends FrontController
if (Tools::isSubmit('submitReorder') AND $id_order = (int)Tools::getValue('id_order')) if (Tools::isSubmit('submitReorder') AND $id_order = (int)Tools::getValue('id_order'))
{ {
$oldCart = new Cart(Order::getCartIdStatic((int)$id_order, (int)self::$cookie->id_customer)); $oldCart = new Cart(Order::getCartIdStatic($id_order, $context->customer->id));
$duplication = $oldCart->duplicate(); $duplication = $oldCart->duplicate();
if (!$duplication OR !Validate::isLoadedObject($duplication['cart'])) if (!$duplication OR !Validate::isLoadedObject($duplication['cart']))
$this->errors[] = Tools::displayError('Sorry, we cannot renew your order.'); $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.');
@@ -77,8 +78,8 @@ class ParentOrderControllerCore extends FrontController
$this->errors[] = Tools::displayError('Missing items - we are unable to renew your order'); $this->errors[] = Tools::displayError('Missing items - we are unable to renew your order');
else else
{ {
self::$cookie->id_cart = $duplication['cart']->id; $context->cookie->id_cart = $duplication['cart']->id;
self::$cookie->write(); $context->cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
Tools::redirect('index.php?controller=order-opc'); Tools::redirect('index.php?controller=order-opc');
Tools::redirect('index.php?controller=order'); Tools::redirect('index.php?controller=order');
@@ -97,14 +98,14 @@ class ParentOrderControllerCore extends FrontController
$discount = new Discount((int)(Discount::getIdByName($discountName))); $discount = new Discount((int)(Discount::getIdByName($discountName)));
if (Validate::isLoadedObject($discount)) if (Validate::isLoadedObject($discount))
{ {
if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true, (int)$this->id_current_group_shop, (int)$this->id_current_shop)) if ($tmpError = $context->cart->checkDiscountValidity($discount, $context->cart->getDiscounts(), $context->cart->getOrderTotal(), $context->cart->getProducts(), true, (int)$this->id_current_group_shop, (int)$this->id_current_shop))
$this->errors[] = $tmpError; $this->errors[] = $tmpError;
} }
else else
$this->errors[] = Tools::displayError('Voucher name invalid.'); $this->errors[] = Tools::displayError('Voucher name invalid.');
if (!sizeof($this->errors)) if (!sizeof($this->errors))
{ {
self::$cart->addDiscount((int)($discount->id)); $context->cart->addDiscount((int)($discount->id));
Tools::redirect('index.php?controller=order-opc'); Tools::redirect('index.php?controller=order-opc');
} }
} }
@@ -115,12 +116,12 @@ class ParentOrderControllerCore extends FrontController
} }
elseif (isset($_GET['deleteDiscount']) AND Validate::isUnsignedId($_GET['deleteDiscount'])) elseif (isset($_GET['deleteDiscount']) AND Validate::isUnsignedId($_GET['deleteDiscount']))
{ {
self::$cart->deleteDiscount((int)($_GET['deleteDiscount'])); $context->cart->deleteDiscount((int)($_GET['deleteDiscount']));
Tools::redirect('index.php?controller=order-opc'); Tools::redirect('index.php?controller=order-opc');
} }
/* Is there only virtual product in cart */ /* Is there only virtual product in cart */
if ($isVirtualCart = self::$cart->isVirtualCart()) if ($isVirtualCart = $context->cart->isVirtualCart())
$this->_setNoCarrier(); $this->_setNoCarrier();
} }
@@ -153,23 +154,25 @@ class ParentOrderControllerCore extends FrontController
*/ */
protected function _checkFreeOrder() protected function _checkFreeOrder()
{ {
if (self::$cart->getOrderTotal() <= 0) $context = Context::getContext();
if ($context->cart->getOrderTotal() <= 0)
{ {
$order = new FreeOrder(); $order = new FreeOrder();
$order->free_order_class = true; $order->free_order_class = true;
$order->validateOrder((int)(self::$cart->id), _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false)); $order->validateOrder($context->cart->id, _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false));
return (int)Order::getOrderByCartId((int)self::$cart->id); return (int)Order::getOrderByCartId($context->cart->id);
} }
return false; return false;
} }
protected function _updateMessage($messageContent) protected function _updateMessage($messageContent)
{ {
$context = Context::getContext();
if ($messageContent) if ($messageContent)
{ {
if (!Validate::isMessage($messageContent)) if (!Validate::isMessage($messageContent))
$this->errors[] = Tools::displayError('Invalid message'); $this->errors[] = Tools::displayError('Invalid message');
elseif ($oldMessage = Message::getMessageByCartId((int)(self::$cart->id))) elseif ($oldMessage = Message::getMessageByCartId((int)($context->cart->id)))
{ {
$message = new Message((int)($oldMessage['id_message'])); $message = new Message((int)($oldMessage['id_message']));
$message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8'); $message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8');
@@ -179,16 +182,16 @@ class ParentOrderControllerCore extends FrontController
{ {
$message = new Message(); $message = new Message();
$message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8'); $message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8');
$message->id_cart = (int)(self::$cart->id); $message->id_cart = (int)($context->cart->id);
$message->id_customer = (int)(self::$cart->id_customer); $message->id_customer = (int)($context->cart->id_customer);
$message->add(); $message->add();
} }
} }
else else
{ {
if ($oldMessage = Message::getMessageByCartId((int)(self::$cart->id))) if ($oldMessage = Message::getMessageByCartId($context->cart->id))
{ {
$message = new Message((int)($oldMessage['id_message'])); $message = new Message($oldMessage['id_message']);
$message->delete(); $message->delete();
} }
} }
@@ -197,19 +200,20 @@ class ParentOrderControllerCore extends FrontController
protected function _processCarrier() protected function _processCarrier()
{ {
self::$cart->recyclable = (int)(Tools::getValue('recyclable')); $context = Context::getContext();
self::$cart->gift = (int)(Tools::getValue('gift')); $context->cart->recyclable = (int)(Tools::getValue('recyclable'));
$context->cart->gift = (int)(Tools::getValue('gift'));
if ((int)(Tools::getValue('gift'))) if ((int)(Tools::getValue('gift')))
{ {
if (!Validate::isMessage($_POST['gift_message'])) if (!Validate::isMessage($_POST['gift_message']))
$this->errors[] = Tools::displayError('Invalid gift message'); $this->errors[] = Tools::displayError('Invalid gift message');
else else
self::$cart->gift_message = strip_tags($_POST['gift_message']); $context->cart->gift_message = strip_tags($_POST['gift_message']);
} }
if (isset(self::$cookie->id_customer) AND self::$cookie->id_customer) if (isset($context->customer->id) AND $context->customer->id)
{ {
$address = new Address((int)(self::$cart->id_address_delivery)); $address = new Address((int)($context->cart->id_address_delivery));
if (!($id_zone = Address::getZoneById($address->id))) if (!($id_zone = Address::getZoneById($address->id)))
$this->errors[] = Tools::displayError('No zone match with your address'); $this->errors[] = Tools::displayError('No zone match with your address');
} }
@@ -217,23 +221,22 @@ class ParentOrderControllerCore extends FrontController
$id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT')); $id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'));
if (Validate::isInt(Tools::getValue('id_carrier')) AND sizeof(Carrier::checkCarrierZone((int)(Tools::getValue('id_carrier')), (int)($id_zone)))) if (Validate::isInt(Tools::getValue('id_carrier')) AND sizeof(Carrier::checkCarrierZone((int)(Tools::getValue('id_carrier')), (int)($id_zone))))
self::$cart->id_carrier = (int)(Tools::getValue('id_carrier')); $context->cart->id_carrier = (int)(Tools::getValue('id_carrier'));
elseif (!self::$cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0) elseif (!$context->cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0)
$this->errors[] = Tools::displayError('Invalid carrier or no carrier selected'); $this->errors[] = Tools::displayError('Invalid carrier or no carrier selected');
Module::hookExec('processCarrier', array('cart' => self::$cart)); Module::hookExec('processCarrier', array('cart' => $context->cart));
return self::$cart->update(); return $context->cart->update();
} }
protected function _assignSummaryInformations() protected function _assignSummaryInformations()
{ {
global $currency; $context = Context::getContext();
if (file_exists(_PS_SHIP_IMG_DIR_.$context->cart->id_carrier.'.jpg'))
if (file_exists(_PS_SHIP_IMG_DIR_.(int)(self::$cart->id_carrier).'.jpg'))
$this->smarty->assign('carrierPicture', 1); $this->smarty->assign('carrierPicture', 1);
$summary = self::$cart->getSummaryDetails(); $summary = $context->cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas((int)(self::$cart->id)); $customizedDatas = Product::getAllCustomizedDatas($context->cart->id);
// override customization tax rate with real tax (tax rules) // override customization tax rate with real tax (tax rules)
foreach($summary['products'] AS &$productUpdate) foreach($summary['products'] AS &$productUpdate)
@@ -242,14 +245,14 @@ class ParentOrderControllerCore extends FrontController
$productAttributeId = (int)(isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']); $productAttributeId = (int)(isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']);
if (isset($customizedDatas[$productId][$productAttributeId])) if (isset($customizedDatas[$productId][$productAttributeId]))
$productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, self::$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
} }
Product::addCustomizationPrice($summary['products'], $customizedDatas); Product::addCustomizationPrice($summary['products'], $customizedDatas);
if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency((int)(self::$cart->id_currency)))) if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency($context->cart->id_currency)))
{ {
$discounts = self::$cart->getDiscounts(); $discounts = $context->cart->getDiscounts();
$total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']); $total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']);
foreach ($discounts as $discount) foreach ($discounts as $discount)
if ($discount['id_discount_type'] == 3) if ($discount['id_discount_type'] == 3)
@@ -266,20 +269,20 @@ class ParentOrderControllerCore extends FrontController
$this->smarty->assign($summary); $this->smarty->assign($summary);
$this->smarty->assign(array( $this->smarty->assign(array(
'token_cart' => Tools::getToken(false), 'token_cart' => Tools::getToken(false),
'isVirtualCart' => self::$cart->isVirtualCart(), 'isVirtualCart' => $context->cart->isVirtualCart(),
'productNumber' => self::$cart->nbProducts(), 'productNumber' => $context->cart->nbProducts(),
'voucherAllowed' => Configuration::get('PS_VOUCHERS'), 'voucherAllowed' => Configuration::get('PS_VOUCHERS'),
'shippingCost' => self::$cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCost' => $context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING),
'shippingCostTaxExc' => self::$cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING),
'customizedDatas' => $customizedDatas, 'customizedDatas' => $customizedDatas,
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
'lastProductAdded' => self::$cart->getLastProduct(), 'lastProductAdded' => $context->cart->getLastProduct(),
'displayVouchers' => Discount::getVouchersToCartDisplay((int)(self::$cookie->id_lang), (isset(self::$cookie->id_customer) ? (int)(self::$cookie->id_customer) : 0)), 'displayVouchers' => Discount::getVouchersToCartDisplay($context->language->id, (isset($context->customer->id) ? $context->customer->id : 0)),
'currencySign' => $currency->sign, 'currencySign' => $context->currency->sign,
'currencyRate' => $currency->conversion_rate, 'currencyRate' => $context->currency->conversion_rate,
'currencyFormat' => $currency->format, 'currencyFormat' => $context->currency->format,
'currencyBlank' => $currency->blank)); 'currencyBlank' => $context->currency->blank));
$this->smarty->assign(array( $this->smarty->assign(array(
'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary), 'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary),
'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary) 'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary)
@@ -288,19 +291,20 @@ class ParentOrderControllerCore extends FrontController
protected function _assignAddress() protected function _assignAddress()
{ {
$context = Context::getContext();
//if guest checkout disabled and flag is_guest in cookies is actived //if guest checkout disabled and flag is_guest in cookies is actived
if(Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 AND ((int) self::$cookie->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))) if(Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 AND ((int)$context->customer->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED')))
{ {
self::$cookie->logout(); $context->cookie->logout();
Tools::redirect(''); Tools::redirect('');
} }
elseif (!Customer::getAddressesTotalById((int)(self::$cookie->id_customer))) elseif (!Customer::getAddressesTotalById($context->customer->id))
Tools::redirect('index.php?controller=address&back=order.php&step=1'); Tools::redirect('index.php?controller=address&back=order.php&step=1');
$customer = new Customer((int)(self::$cookie->id_customer)); $customer = $context->customer;
if (Validate::isLoadedObject($customer)) if (Validate::isLoadedObject($customer))
{ {
/* Getting customer addresses */ /* Getting customer addresses */
$customerAddresses = $customer->getAddresses((int)(self::$cookie->id_lang)); $customerAddresses = $customer->getAddresses($context->language->id);
// Getting a list of formated address fields with associated values // Getting a list of formated address fields with associated values
$formatedAddressFieldsValuesList = array(); $formatedAddressFieldsValuesList = array();
@@ -320,46 +324,45 @@ class ParentOrderControllerCore extends FrontController
'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList)); 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList));
/* Setting default addresses for cart */ /* Setting default addresses for cart */
if ((!isset(self::$cart->id_address_delivery) OR empty(self::$cart->id_address_delivery)) AND sizeof($customerAddresses)) if ((!isset($context->cart->id_address_delivery) OR empty($context->cart->id_address_delivery)) AND sizeof($customerAddresses))
{ {
self::$cart->id_address_delivery = (int)($customerAddresses[0]['id_address']); $context->cart->id_address_delivery = (int)($customerAddresses[0]['id_address']);
$update = 1; $update = 1;
} }
if ((!isset(self::$cart->id_address_invoice) OR empty(self::$cart->id_address_invoice)) AND sizeof($customerAddresses)) if ((!isset($context->cart->id_address_invoice) OR empty($context->cart->id_address_invoice)) AND sizeof($customerAddresses))
{ {
self::$cart->id_address_invoice = (int)($customerAddresses[0]['id_address']); $context->cart->id_address_invoice = (int)($customerAddresses[0]['id_address']);
$update = 1; $update = 1;
} }
/* Update cart addresses only if needed */ /* Update cart addresses only if needed */
if (isset($update) AND $update) if (isset($update) AND $update)
self::$cart->update(); $context->cart->update();
/* If delivery address is valid in cart, assign it to Smarty */ /* If delivery address is valid in cart, assign it to Smarty */
if (isset(self::$cart->id_address_delivery)) if (isset($context->cart->id_address_delivery))
{ {
$deliveryAddress = new Address((int)(self::$cart->id_address_delivery)); $deliveryAddress = new Address((int)($context->cart->id_address_delivery));
if (Validate::isLoadedObject($deliveryAddress) AND ($deliveryAddress->id_customer == $customer->id)) if (Validate::isLoadedObject($deliveryAddress) AND ($deliveryAddress->id_customer == $customer->id))
$this->smarty->assign('delivery', $deliveryAddress); $this->smarty->assign('delivery', $deliveryAddress);
} }
/* If invoice address is valid in cart, assign it to Smarty */ /* If invoice address is valid in cart, assign it to Smarty */
if (isset(self::$cart->id_address_invoice)) if (isset($context->cart->id_address_invoice))
{ {
$invoiceAddress = new Address((int)(self::$cart->id_address_invoice)); $invoiceAddress = new Address((int)($context->cart->id_address_invoice));
if (Validate::isLoadedObject($invoiceAddress) AND ($invoiceAddress->id_customer == $customer->id)) if (Validate::isLoadedObject($invoiceAddress) AND ($invoiceAddress->id_customer == $customer->id))
$this->smarty->assign('invoice', $invoiceAddress); $this->smarty->assign('invoice', $invoiceAddress);
} }
} }
if ($oldMessage = Message::getMessageByCartId((int)(self::$cart->id))) if ($oldMessage = Message::getMessageByCartId((int)($context->cart->id)))
$this->smarty->assign('oldMessage', $oldMessage['message']); $this->smarty->assign('oldMessage', $oldMessage['message']);
} }
protected function _assignCarrier() protected function _assignCarrier()
{ {
$customer = new Customer((int)(self::$cookie->id_customer)); $address = new Address($context->cart->id_address_delivery);
$address = new Address((int)(self::$cart->id_address_delivery)); $id_zone = Address::getZoneById($address->id);
$id_zone = Address::getZoneById((int)($address->id)); $carriers = Carrier::getCarriersForOrder($id_zone, Context::getContext()->customer->id->getGroups());
$carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups());
$this->smarty->assign(array( $this->smarty->assign(array(
'checked' => $this->_setDefaultCarrierSelection($carriers), 'checked' => $this->_setDefaultCarrierSelection($carriers),
@@ -372,30 +375,31 @@ class ParentOrderControllerCore extends FrontController
protected function _assignWrappingAndTOS() protected function _assignWrappingAndTOS()
{ {
$context = Context::getContext();
// Wrapping fees // Wrapping fees
$wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE'));
$wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees_tax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX'));
$wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100)));
// TOS // TOS
$cms = new CMS((int)(Configuration::get('PS_CONDITIONS_CMS_ID')), (int)(self::$cookie->id_lang)); $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $context->language->id);
$this->link_conditions = self::$link->getCMSLink($cms, $cms->link_rewrite, true); $this->link_conditions = $context->link->getCMSLink($cms, $cms->link_rewrite, true);
if (!strpos($this->link_conditions, '?')) if (!strpos($this->link_conditions, '?'))
$this->link_conditions .= '?content_only=1'; $this->link_conditions .= '?content_only=1';
else else
$this->link_conditions .= '&content_only=1'; $this->link_conditions .= '&content_only=1';
$this->smarty->assign(array( $this->smarty->assign(array(
'checkedTOS' => (int)(self::$cookie->checkedTOS), 'checkedTOS' => (int)($context->cookie->checkedTOS),
'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')), 'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')),
'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')), 'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')),
'cms_id' => (int)(Configuration::get('PS_CONDITIONS_CMS_ID')), 'cms_id' => (int)(Configuration::get('PS_CONDITIONS_CMS_ID')),
'conditions' => (int)(Configuration::get('PS_CONDITIONS')), 'conditions' => (int)(Configuration::get('PS_CONDITIONS')),
'link_conditions' => $this->link_conditions, 'link_conditions' => $this->link_conditions,
'recyclable' => (int)(self::$cart->recyclable), 'recyclable' => (int)($context->cart->recyclable),
'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')), 'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')),
'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency))), 'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, $context->currency),
'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, new Currency((int)(self::$cookie->id_currency))))); 'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, $context->currency)));
} }
protected function _assignPayment() protected function _assignPayment()
@@ -412,8 +416,9 @@ class ParentOrderControllerCore extends FrontController
*/ */
protected function _setNoCarrier() protected function _setNoCarrier()
{ {
self::$cart->id_carrier = 0; $context = Context::getContext();
self::$cart->update(); $context->cart->id_carrier = 0;
$context->cart->update();
} }
/** /**
@@ -424,27 +429,28 @@ class ParentOrderControllerCore extends FrontController
*/ */
protected function _setDefaultCarrierSelection($carriers) protected function _setDefaultCarrierSelection($carriers)
{ {
$context = Context::getContext();
if (sizeof($carriers)) if (sizeof($carriers))
{ {
$defaultCarrierIsPresent = false; $defaultCarrierIsPresent = false;
if ((int)self::$cart->id_carrier != 0) if ((int)$context->cart->id_carrier != 0)
foreach ($carriers AS $carrier) foreach ($carriers AS $carrier)
if ($carrier['id_carrier'] == (int)self::$cart->id_carrier) if ($carrier['id_carrier'] == (int)$context->cart->id_carrier)
$defaultCarrierIsPresent = true; $defaultCarrierIsPresent = true;
if (!$defaultCarrierIsPresent) if (!$defaultCarrierIsPresent)
foreach ($carriers AS $carrier) foreach ($carriers AS $carrier)
if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT')) if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT'))
{ {
$defaultCarrierIsPresent = true; $defaultCarrierIsPresent = true;
self::$cart->id_carrier = (int)$carrier['id_carrier']; $context->cart->id_carrier = (int)$carrier['id_carrier'];
} }
if (!$defaultCarrierIsPresent) if (!$defaultCarrierIsPresent)
self::$cart->id_carrier = (int)$carriers[0]['id_carrier']; $context->cart->id_carrier = (int)$carriers[0]['id_carrier'];
} }
else else
self::$cart->id_carrier = 0; $context->cart->id_carrier = 0;
if (self::$cart->update()) if ($context->cart->update())
return self::$cart->id_carrier; return $context->cart->id_carrier;
return 0; return 0;
} }
+9 -10
View File
@@ -36,7 +36,7 @@ class StoresControllerCore extends FrontController
public function preProcess() public function preProcess()
{ {
global $smarty, $cookie; $context = Context::getContext();
$simplifiedStoreLocator = Configuration::get('PS_STORES_SIMPLIFIED'); $simplifiedStoreLocator = Configuration::get('PS_STORES_SIMPLIFIED');
$distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); $distanceUnit = Configuration::get('PS_DISTANCE_UNIT');
@@ -51,7 +51,7 @@ class StoresControllerCore extends FrontController
LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store)
LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
WHERE s.active = 1 AND cl.id_lang = '.(int)($cookie->id_lang).' AND ss.id_shop='.(int)$this->id_current_shop); WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop='.(int)$this->id_current_shop);
foreach ($stores AS &$store) foreach ($stores AS &$store)
$store['has_picture'] = file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg'); $store['has_picture'] = file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg');
@@ -66,7 +66,7 @@ class StoresControllerCore extends FrontController
LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store)
LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
WHERE s.active = 1 AND cl.id_lang = '.(int)($cookie->id_lang).' AND ss.id_shop='.(int)$this->id_current_shop); WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop='.(int)$this->id_current_shop);
} }
else else
{ {
@@ -80,7 +80,7 @@ class StoresControllerCore extends FrontController
LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store)
LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
WHERE s.active = 1 AND cl.id_lang = '.(int)($cookie->id_lang).' AND ss.id_shop='.(int)$this->id_current_shop.' WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop='.(int)$this->id_current_shop.'
HAVING distance < '.(int)($distance).' HAVING distance < '.(int)($distance).'
ORDER BY distance ASC ORDER BY distance ASC
LIMIT 0,20'); LIMIT 0,20');
@@ -120,8 +120,8 @@ class StoresControllerCore extends FrontController
$hours_datas['hours'] = $hours[(int)($i) - 1]; $hours_datas['hours'] = $hours[(int)($i) - 1];
$days_datas[] = $hours_datas; $days_datas[] = $hours_datas;
} }
$smarty->assign('days_datas', $days_datas); $this->smarty->assign('days_datas', $days_datas);
$smarty->assign('id_country', $store['id_country']); $this->smarty->assign('id_country', $store['id_country']);
$other .= $this->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); $other .= $this->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl');
} }
@@ -143,10 +143,10 @@ class StoresControllerCore extends FrontController
die($dom->saveXML()); die($dom->saveXML());
} }
else else
$smarty->assign('hasStoreIcon', file_exists(dirname(__FILE__).'/../img/logo_stores.gif')); $this->smarty->assign('hasStoreIcon', file_exists(dirname(__FILE__).'/../img/logo_stores.gif'));
} }
$smarty->assign(array('distance_unit' => $distanceUnit, 'simplifiedStoresDiplay' => $simplifiedStoreLocator, 'stores' => $stores, 'mediumSize' => Image::getSize('medium'))); $this->smarty->assign(array('distance_unit' => $distanceUnit, 'simplifiedStoresDiplay' => $simplifiedStoreLocator, 'stores' => $stores, 'mediumSize' => Image::getSize('medium')));
} }
private function _processStoreAddress($store) private function _processStoreAddress($store)
@@ -189,13 +189,12 @@ class StoresControllerCore extends FrontController
public function process() public function process()
{ {
global $link;
parent::process(); parent::process();
$this->smarty->assign(array( $this->smarty->assign(array(
'defaultLat' => (float)Configuration::get('PS_STORES_CENTER_LAT'), 'defaultLat' => (float)Configuration::get('PS_STORES_CENTER_LAT'),
'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'), 'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'),
'searchUrl' => $link->getPageLink('stores') 'searchUrl' => Context::getContext()->link->getPageLink('stores')
)); ));
} }