// 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
2011-07-15 16:41:39 +00:00
parent 20276404a8
commit 311e8ab964
10 changed files with 163 additions and 161 deletions
+8 -8
View File
@@ -100,7 +100,7 @@ class FrontControllerCore
ob_start();
$cookie = new Cookie('ps');
$context->cookie = $cookie;
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
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')))
$this->maintenance = true;
elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
if ($newDefault = $this->geolocationManagement() && Validate::isLoadedObject($newDefault))
if (($newDefault = $this->geolocationManagement($defaultCountry)) && Validate::isLoadedObject($newDefault))
$defaultCountry = $newDefault;
// Switch language if needed and init cookie language
@@ -388,10 +388,10 @@ class FrontControllerCore
}
}
protected function geolocationManagement()
protected function geolocationManagement($defaultCountry)
{
$context = Context::getContext();
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
{
/* Check if Maxmind Database exists */
@@ -403,7 +403,7 @@ class FrontControllerCore
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
$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))
{
@@ -425,11 +425,11 @@ class FrontControllerCore
}
}
if (isset($context->cookie->iso_code_country)
&& (int)($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
if (isset($context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
{
/* 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)
$context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
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)
{
global $link;
if (!$context)
$context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
@@ -223,7 +222,7 @@ class SceneCore extends ObjectModel
foreach ($products AS &$product)
{
$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);
if(is_array($cover))
$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)
{
global $cookie;
if (!$id_lang)
$id_lang = Configuration::get('PS_LANG_DEFAULT');
$query = 'SELECT s.*, sl.`description`';
+5 -5
View File
@@ -78,11 +78,11 @@ class TabCore extends ObjectModel
return false;
}
static public function initAccess($id_tab)
static public function initAccess($id_tab, $context = null)
{
/* Cookie's loading */
global $cookie;
if (!is_object($cookie) OR !$cookie->profile)
if (!$context)
$context = Context::getContext();
if (!$context->employee->id_profile)
return false;
/* Profile selection */
$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 ';
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.')';
}
return Db::getInstance()->Execute($query);
+4 -3
View File
@@ -161,10 +161,11 @@ class TagCore extends ObjectModel
return $result;
}
public function getProducts($associated = true)
public function getProducts($associated = true, $context = null)
{
global $cookie;
$id_lang = $this->id_lang ? $this->id_lang : $cookie->id_lang;
if (!$context)
$context = Context::getContext();
$id_lang = $this->id_lang ? $this->id_lang : $context->language->id;
if (!$this->id AND $associated)
return array();
-2
View File
@@ -231,8 +231,6 @@ class TaxCore extends ObjectModel
public static function getApplicableTaxRate($id_tax, $productTax, $id_address = NULL)
{
Tools::displayAsDeprecated();
global $cart, $cookie, $defaultCountry;
return $productTax;
}
+45 -44
View File
@@ -55,11 +55,10 @@ class ToolsCore
* @param string $url Desired URL
* @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)
{
global $link;
if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0)
$url = substr($url, strlen($baseUri));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0) {
@@ -69,7 +68,7 @@ class ToolsCore
}
$explode = explode('?', $url);
$url = $link->getPageLink($explode[0], true);
$url = $context->link->getPageLink($explode[0], true);
if (isset($explode[1]))
$url .= '?'.$explode[1];
$baseUri = '';
@@ -91,17 +90,15 @@ class ToolsCore
{
if (!preg_match('@^https?://@i', $url))
{
global $link;
if (strpos($url, __PS_BASE_URI__) !== FALSE && strpos($url, __PS_BASE_URI__) == 0)
$url = substr($url, strlen(__PS_BASE_URI__));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0)
$url = substr($url, strlen('index.php?controller='));
$explode = explode('?', $url);
$url = $link->getPageLink($explode[0]);
$url = $context->link->getPageLink($explode[0]);
if (isset($explode[1]))
$url .= '?'.$explode[1];
}
header('Location: '.$url);
exit;
}
@@ -528,12 +525,11 @@ class ToolsCore
*
* @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_.$iso.'/errors.php');
@include_once(_PS_TRANSLATIONS_DIR_.$context->language->iso_code.'/errors.php');
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $string == 'Fatal error')
return ('<pre>'.print_r(debug_backtrace(), true).'</pre>');
@@ -715,8 +711,6 @@ class ToolsCore
*/
public static function getHomeMetaTags($id_lang, $page_name)
{
global $cookie;
/* Metas-tags */
$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');
@@ -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)
$metaTags['meta_title'] = $defaultValue.' - '.Configuration::get('PS_SHOP_NAME');
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)
$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;
}
@@ -754,13 +749,14 @@ class ToolsCore
*
* @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)
return (self::encrypt($cookie->id_customer.$cookie->passwd.$_SERVER['SCRIPT_NAME']));
return (self::encrypt($context->customer->id.$context->customer->passwd.$_SERVER['SCRIPT_NAME']));
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;
}
public static function getAdminTokenLite($tab)
public static function getAdminTokenLite($tab, $context = null)
{
global $cookie;
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$cookie->id_employee);
if (!$context)
$context = Context::getContext();
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$context->employee->id);
}
/**
@@ -786,10 +783,11 @@ class ToolsCore
* @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)
*/
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)
return '<span class="navigation_end">'.$path.'</span>';
@@ -812,7 +810,7 @@ class ToolsCore
SELECT c.id_category, cl.name, cl.link_rewrite
FROM '._DB_PREFIX_.'category c
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
LIMIT '.(int)$category['level_depth']);
@@ -821,7 +819,7 @@ class ToolsCore
foreach ($categories AS $category)
{
$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').
(($n < $nCategories OR $linkOntheLastItem) ? '</a>' : '').
(($n++ != $nCategories OR !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');
@@ -832,10 +830,10 @@ class ToolsCore
}
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))
die(self::displayError());
$categoryLink = $link->getCMSCategoryLink($category);
$categoryLink = $context->link->getCMSCategoryLink($category);
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;
@@ -849,16 +847,17 @@ class ToolsCore
/**
* @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') : '>');
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')
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang));
$category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category))
$id_category = 1;
@@ -914,11 +913,10 @@ class ToolsCore
*/
public static function historyc_l($key, $translations)
{
global $cookie;
if (!$translations OR !is_array($translations))
die(self::displayError());
$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);
}
@@ -1375,7 +1373,7 @@ class ToolsCore
public static function replaceByAbsoluteURL($matches)
{
global $current_css_file, $protocol_link;
global $current_css_file;
$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'))
return;
if ($smarty->force_compile == 0 AND $smarty->caching == $level)
@@ -1871,10 +1870,12 @@ FileETag INode MTime Size
$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))
$smarty->force_compile = (int)(self::$_forceCompile);
if (isset(self::$_caching))
+5 -5
View File
@@ -141,15 +141,15 @@ class OrderControllerCore extends ParentOrderController
public function displayContent()
{
global $currency;
$context = Context::getContext();
parent::displayContent();
$this->smarty->assign(array(
'currencySign' => $currency->sign,
'currencyRate' => $currency->conversion_rate,
'currencyFormat' => $currency->format,
'currencyBlank' => $currency->blank,
'currencySign' => $context->currency->sign,
'currencyRate' => $context->currency->conversion_rate,
'currencyFormat' => $context->currency->format,
'currencyBlank' => $context->currency->blank,
));
switch ((int)$this->step)
+85 -79
View File
@@ -45,13 +45,14 @@ class ParentOrderControllerCore extends FrontController
public function init()
{
parent::init();
$this->nbProducts = self::$cart->nbProducts();
$context = Context::getContext();
$this->nbProducts = $context->cart->nbProducts();
}
public function preProcess()
{
global $isVirtualCart;
$context = Context::getContext();
parent::preProcess();
// 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'))
{
$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();
if (!$duplication OR !Validate::isLoadedObject($duplication['cart']))
$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');
else
{
self::$cookie->id_cart = $duplication['cart']->id;
self::$cookie->write();
$context->cookie->id_cart = $duplication['cart']->id;
$context->cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
Tools::redirect('index.php?controller=order-opc');
Tools::redirect('index.php?controller=order');
@@ -97,14 +98,14 @@ class ParentOrderControllerCore extends FrontController
$discount = new Discount((int)(Discount::getIdByName($discountName)));
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;
}
else
$this->errors[] = Tools::displayError('Voucher name invalid.');
if (!sizeof($this->errors))
{
self::$cart->addDiscount((int)($discount->id));
$context->cart->addDiscount((int)($discount->id));
Tools::redirect('index.php?controller=order-opc');
}
}
@@ -115,12 +116,12 @@ class ParentOrderControllerCore extends FrontController
}
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');
}
/* Is there only virtual product in cart */
if ($isVirtualCart = self::$cart->isVirtualCart())
if ($isVirtualCart = $context->cart->isVirtualCart())
$this->_setNoCarrier();
}
@@ -153,23 +154,25 @@ class ParentOrderControllerCore extends FrontController
*/
protected function _checkFreeOrder()
{
if (self::$cart->getOrderTotal() <= 0)
$context = Context::getContext();
if ($context->cart->getOrderTotal() <= 0)
{
$order = new FreeOrder();
$order->free_order_class = true;
$order->validateOrder((int)(self::$cart->id), _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false));
return (int)Order::getOrderByCartId((int)self::$cart->id);
$order->validateOrder($context->cart->id, _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false));
return (int)Order::getOrderByCartId($context->cart->id);
}
return false;
}
protected function _updateMessage($messageContent)
{
$context = Context::getContext();
if ($messageContent)
{
if (!Validate::isMessage($messageContent))
$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->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8');
@@ -179,16 +182,16 @@ class ParentOrderControllerCore extends FrontController
{
$message = new Message();
$message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8');
$message->id_cart = (int)(self::$cart->id);
$message->id_customer = (int)(self::$cart->id_customer);
$message->id_cart = (int)($context->cart->id);
$message->id_customer = (int)($context->cart->id_customer);
$message->add();
}
}
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();
}
}
@@ -197,19 +200,20 @@ class ParentOrderControllerCore extends FrontController
protected function _processCarrier()
{
self::$cart->recyclable = (int)(Tools::getValue('recyclable'));
self::$cart->gift = (int)(Tools::getValue('gift'));
$context = Context::getContext();
$context->cart->recyclable = (int)(Tools::getValue('recyclable'));
$context->cart->gift = (int)(Tools::getValue('gift'));
if ((int)(Tools::getValue('gift')))
{
if (!Validate::isMessage($_POST['gift_message']))
$this->errors[] = Tools::displayError('Invalid gift message');
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)))
$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'));
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'));
elseif (!self::$cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0)
$context->cart->id_carrier = (int)(Tools::getValue('id_carrier'));
elseif (!$context->cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0)
$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()
{
global $currency;
if (file_exists(_PS_SHIP_IMG_DIR_.(int)(self::$cart->id_carrier).'.jpg'))
$context = Context::getContext();
if (file_exists(_PS_SHIP_IMG_DIR_.$context->cart->id_carrier.'.jpg'))
$this->smarty->assign('carrierPicture', 1);
$summary = self::$cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas((int)(self::$cart->id));
$summary = $context->cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas($context->cart->id);
// override customization tax rate with real tax (tax rules)
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']);
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);
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']);
foreach ($discounts as $discount)
if ($discount['id_discount_type'] == 3)
@@ -266,20 +269,20 @@ class ParentOrderControllerCore extends FrontController
$this->smarty->assign($summary);
$this->smarty->assign(array(
'token_cart' => Tools::getToken(false),
'isVirtualCart' => self::$cart->isVirtualCart(),
'productNumber' => self::$cart->nbProducts(),
'isVirtualCart' => $context->cart->isVirtualCart(),
'productNumber' => $context->cart->nbProducts(),
'voucherAllowed' => Configuration::get('PS_VOUCHERS'),
'shippingCost' => self::$cart->getOrderTotal(true, Cart::ONLY_SHIPPING),
'shippingCostTaxExc' => self::$cart->getOrderTotal(false, Cart::ONLY_SHIPPING),
'shippingCost' => $context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING),
'shippingCostTaxExc' => $context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING),
'customizedDatas' => $customizedDatas,
'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_,
'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_,
'lastProductAdded' => self::$cart->getLastProduct(),
'displayVouchers' => Discount::getVouchersToCartDisplay((int)(self::$cookie->id_lang), (isset(self::$cookie->id_customer) ? (int)(self::$cookie->id_customer) : 0)),
'currencySign' => $currency->sign,
'currencyRate' => $currency->conversion_rate,
'currencyFormat' => $currency->format,
'currencyBlank' => $currency->blank));
'lastProductAdded' => $context->cart->getLastProduct(),
'displayVouchers' => Discount::getVouchersToCartDisplay($context->language->id, (isset($context->customer->id) ? $context->customer->id : 0)),
'currencySign' => $context->currency->sign,
'currencyRate' => $context->currency->conversion_rate,
'currencyFormat' => $context->currency->format,
'currencyBlank' => $context->currency->blank));
$this->smarty->assign(array(
'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary),
'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary)
@@ -288,19 +291,20 @@ class ParentOrderControllerCore extends FrontController
protected function _assignAddress()
{
$context = Context::getContext();
//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('');
}
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');
$customer = new Customer((int)(self::$cookie->id_customer));
$customer = $context->customer;
if (Validate::isLoadedObject($customer))
{
/* 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
$formatedAddressFieldsValuesList = array();
@@ -320,46 +324,45 @@ class ParentOrderControllerCore extends FrontController
'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList));
/* 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;
}
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 cart addresses only if needed */
if (isset($update) AND $update)
self::$cart->update();
$context->cart->update();
/* 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))
$this->smarty->assign('delivery', $deliveryAddress);
}
/* 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))
$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']);
}
protected function _assignCarrier()
{
$customer = new Customer((int)(self::$cookie->id_customer));
$address = new Address((int)(self::$cart->id_address_delivery));
$id_zone = Address::getZoneById((int)($address->id));
$carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups());
$address = new Address($context->cart->id_address_delivery);
$id_zone = Address::getZoneById($address->id);
$carriers = Carrier::getCarriersForOrder($id_zone, Context::getContext()->customer->id->getGroups());
$this->smarty->assign(array(
'checked' => $this->_setDefaultCarrierSelection($carriers),
@@ -372,30 +375,31 @@ class ParentOrderControllerCore extends FrontController
protected function _assignWrappingAndTOS()
{
$context = Context::getContext();
// Wrapping fees
$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)));
// TOS
$cms = new CMS((int)(Configuration::get('PS_CONDITIONS_CMS_ID')), (int)(self::$cookie->id_lang));
$this->link_conditions = self::$link->getCMSLink($cms, $cms->link_rewrite, true);
$cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $context->language->id);
$this->link_conditions = $context->link->getCMSLink($cms, $cms->link_rewrite, true);
if (!strpos($this->link_conditions, '?'))
$this->link_conditions .= '?content_only=1';
else
$this->link_conditions .= '&content_only=1';
$this->smarty->assign(array(
'checkedTOS' => (int)(self::$cookie->checkedTOS),
'checkedTOS' => (int)($context->cookie->checkedTOS),
'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')),
'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')),
'cms_id' => (int)(Configuration::get('PS_CONDITIONS_CMS_ID')),
'conditions' => (int)(Configuration::get('PS_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')),
'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency))),
'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, 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, $context->currency)));
}
protected function _assignPayment()
@@ -412,8 +416,9 @@ class ParentOrderControllerCore extends FrontController
*/
protected function _setNoCarrier()
{
self::$cart->id_carrier = 0;
self::$cart->update();
$context = Context::getContext();
$context->cart->id_carrier = 0;
$context->cart->update();
}
/**
@@ -424,27 +429,28 @@ class ParentOrderControllerCore extends FrontController
*/
protected function _setDefaultCarrierSelection($carriers)
{
$context = Context::getContext();
if (sizeof($carriers))
{
$defaultCarrierIsPresent = false;
if ((int)self::$cart->id_carrier != 0)
if ((int)$context->cart->id_carrier != 0)
foreach ($carriers AS $carrier)
if ($carrier['id_carrier'] == (int)self::$cart->id_carrier)
if ($carrier['id_carrier'] == (int)$context->cart->id_carrier)
$defaultCarrierIsPresent = true;
if (!$defaultCarrierIsPresent)
foreach ($carriers AS $carrier)
if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT'))
{
$defaultCarrierIsPresent = true;
self::$cart->id_carrier = (int)$carrier['id_carrier'];
$context->cart->id_carrier = (int)$carrier['id_carrier'];
}
if (!$defaultCarrierIsPresent)
self::$cart->id_carrier = (int)$carriers[0]['id_carrier'];
$context->cart->id_carrier = (int)$carriers[0]['id_carrier'];
}
else
self::$cart->id_carrier = 0;
if (self::$cart->update())
return self::$cart->id_carrier;
$context->cart->id_carrier = 0;
if ($context->cart->update())
return $context->cart->id_carrier;
return 0;
}
+10 -11
View File
@@ -36,8 +36,8 @@ class StoresControllerCore extends FrontController
public function preProcess()
{
global $smarty, $cookie;
$context = Context::getContext();
$simplifiedStoreLocator = Configuration::get('PS_STORES_SIMPLIFIED');
$distanceUnit = Configuration::get('PS_DISTANCE_UNIT');
if (!in_array($distanceUnit, array('km', 'mi')))
@@ -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_.'country_lang cl ON (cl.id_country = s.id_country)
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)
$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_.'country_lang cl ON (cl.id_country = s.id_country)
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
{
@@ -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_.'country_lang cl ON (cl.id_country = s.id_country)
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).'
ORDER BY distance ASC
LIMIT 0,20');
@@ -120,8 +120,8 @@ class StoresControllerCore extends FrontController
$hours_datas['hours'] = $hours[(int)($i) - 1];
$days_datas[] = $hours_datas;
}
$smarty->assign('days_datas', $days_datas);
$smarty->assign('id_country', $store['id_country']);
$this->smarty->assign('days_datas', $days_datas);
$this->smarty->assign('id_country', $store['id_country']);
$other .= $this->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl');
}
@@ -143,10 +143,10 @@ class StoresControllerCore extends FrontController
die($dom->saveXML());
}
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)
@@ -189,13 +189,12 @@ class StoresControllerCore extends FrontController
public function process()
{
global $link;
parent::process();
$this->smarty->assign(array(
'defaultLat' => (float)Configuration::get('PS_STORES_CENTER_LAT'),
'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'),
'searchUrl' => $link->getPageLink('stores')
'searchUrl' => Context::getContext()->link->getPageLink('stores')
));
}