diff --git a/classes/Attribute.php b/classes/Attribute.php index a53bac0ac..1842ae747 100644 --- a/classes/Attribute.php +++ b/classes/Attribute.php @@ -121,7 +121,7 @@ class AttributeCore extends ObjectModel static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null) { if (!$shop) - $$shop = Context::getContext()->shop; + $shop = Context::getContext()->shop; $sql = 'SELECT quantity FROM '._DB_PREFIX_.'stock diff --git a/classes/CMS.php b/classes/CMS.php index 16c7bf3e2..6351622e8 100644 --- a/classes/CMS.php +++ b/classes/CMS.php @@ -104,11 +104,10 @@ class CMSCore extends ObjectModel return false; } - public static function getLinks($id_lang, $selection = NULL, $active = true, Context $context = null) + public static function getLinks($id_lang, $selection = NULL, $active = true, Link $link = null) { - if (!$context) - $context = Context::getContext(); - + if (!$link) + $link = Context::getContext()->link; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.id_cms, cl.link_rewrite, cl.meta_title FROM '._DB_PREFIX_.'cms c @@ -122,7 +121,7 @@ class CMSCore extends ObjectModel if ($result) foreach ($result as $row) { - $row['link'] = $context->link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); + $row['link'] = $link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); $links[] = $row; } return $links; diff --git a/classes/CMSCategory.php b/classes/CMSCategory.php index a313e6ea5..a9b86514c 100644 --- a/classes/CMSCategory.php +++ b/classes/CMSCategory.php @@ -145,31 +145,32 @@ class CMSCategoryCore extends ObjectModel * * @return array Subcategories lite tree */ - function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL, Context $context = null) + function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL, Link $link = null) { - if (!$context) - $context = Context::getContext(); - //get idLang - $idLang = is_null($idLang) ? $context->language->id : (int)($idLang); + if (!$link) + $link = Context::getContext()->link; + + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; //recursivity for subcategories $children = array(); - if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($idLang, true) AND sizeof($subcats)) + if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($id_lang, true) AND sizeof($subcats)) foreach ($subcats as &$subcat) { if (!$subcat['id_cms_category']) break; elseif ( !is_array($excludedIdsArray) || !in_array($subcat['id_cms_category'], $excludedIdsArray) ) { - $categ = new CMSCategory($subcat['id_cms_category'] ,$idLang); + $categ = new CMSCategory($subcat['id_cms_category'] ,$id_lang); $categ->name = CMSCategory::hideCMSCategoryPosition($categ->name); - $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray); + $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray); } } return array( 'id' => $this->id_cms_category, - 'link' => $context->link->getCMSCategoryLink($this->id, $this->link_rewrite), + 'link' => $link->getCMSCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc'=> $this->description, 'children' => $children @@ -467,19 +468,19 @@ class CMSCategoryCore extends ObjectModel return $result['link_rewrite']; } - public function getLink(Context $context = null) + public function getLink(Link $link = null) { - if (!$context) - $context = Context::getContext(); - return $context->link->getCMSCategoryLink($this->id, $this->link_rewrite); + if (!$link) + $link = Context::getContext()->link; + return $link->getCMSCategoryLink($this->id, $this->link_rewrite); } - public function getName($id_lang = NULL, Context $context = null) + public function getName($id_lang = NULL) { if (!$id_lang) { - if (isset($this->name[$context->language->id])) - $id_lang = $context->language->id; + if (isset($this->name[Context::getContext()->language->id])) + $id_lang = Context::getContext()->language->id; else $id_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); } @@ -537,12 +538,10 @@ class CMSCategoryCore extends ObjectModel * @param integer $id_lang Language ID * @return array Corresponding categories */ - public function getParentsCategories($idLang = null, Context $context = null) + public function getParentsCategories($id_lang = null) { - if (!$context) - $context = Context::getContext(); - //get idLang - $idLang = is_null($idLang) ? $context->language->id : $idLang; + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; $categories = null; $idCurrent = $this->id; @@ -551,7 +550,7 @@ class CMSCategoryCore extends ObjectModel $query = ' SELECT c.*, cl.* FROM `'._DB_PREFIX_.'cms_category` c - LEFT JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (c.`id_cms_category` = cl.`id_cms_category` AND `id_lang` = '.(int)$idLang.') + LEFT JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (c.`id_cms_category` = cl.`id_cms_category` AND `id_lang` = '.(int)$id_lang.') WHERE c.`id_cms_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0 '; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query); diff --git a/classes/Cart.php b/classes/Cart.php index 4930f55dc..7a626b177 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -620,7 +620,7 @@ class CartCore extends ObjectModel { $sql = 'SELECT p.out_of_stock, stock.quantity FROM '._DB_PREFIX_.'product p - '.Product::sqlStock('p', $id_product_attribute, true, $context).' + '.Product::sqlStock('p', $id_product_attribute, true, $shop).' WHERE p.id_product = '.$id_product; $result2 = Db::getInstance()->getRow($sql); if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock'])) @@ -634,7 +634,7 @@ class CartCore extends ObjectModel 'id_product' => (int)$id_product, 'id_product_attribute' => (int)$id_product_attribute, 'id_cart' => (int)$this->id, - 'id_shop' => $context->shop->getID(true), + 'id_shop' => $shop->getID(true), 'quantity' => (int)$quantity, 'date_add' => date('Y-m-d H:i:s') ), 'INSERT'); diff --git a/classes/Category.php b/classes/Category.php index 67db4d817..78396ddba 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -184,33 +184,32 @@ class CategoryCore extends ObjectModel * * @param integer $maxDepth Maximum depth of the tree (i.e. 2 => 3 levels depth) * @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!) + * @param integer $id_lang Specify the id of the language used * @param array $excludedIdsArray specify a list of ids to exclude of results - * @param integer $idLang Specify the id of the language used + * @param Link $link * * @return array Subcategories lite tree */ - function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL, Context $context = null) + function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL, Link $link = NULL) { - if (!$context) - $context = Context::getContext(); - $idLang = is_null($idLang) ? $context->language->id : (int)$idLang; + $id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang; $children = array(); - if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($idLang, true) AND sizeof($subcats)) + if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($id_lang, true) AND sizeof($subcats)) foreach ($subcats AS &$subcat) { if (!$subcat['id_category']) break; elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray)) { - $categ = new Category((int)$subcat['id_category'], $idLang); - $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray); + $categ = new Category((int)$subcat['id_category'], $id_lang); + $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray); } } return array( 'id' => (int)$this->id_category, - 'link' => $context->link->getCategoryLink((int)$this->id, $this->link_rewrite), + 'link' => Context::getContext()->link->getCategoryLink($this->id, $this->link_rewrite), 'name' => $this->name, 'desc'=> $this->description, 'children' => $children @@ -507,7 +506,7 @@ class CategoryCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) '.$context->shop->sqlAsso('product', 'p').' - '.Product::sqlStock('p', 'pa', false, $context).' + '.Product::sqlStock('p', 'pa', false, $context->shop).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('cl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) @@ -567,12 +566,14 @@ class CategoryCore extends ObjectModel return self::getChildren(1, $id_lang, $active); } - static public function getRootCategory($id_lang = NULL, Context $context = null) + static public function getRootCategory($id_lang = NULL, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; + if (!$shop) + $shop = Context::getContext()->shop; - return new Category($context->shop->getCategory(), is_null($id_lang) ? $context->language->id : $id_lang); + return new Category($context->shop->getCategory(), $id_lang); } /** @@ -709,22 +710,19 @@ class CategoryCore extends ObjectModel return $result['link_rewrite']; } - public function getLink(Context $context = null) + public function getLink(Link $link = null) { - if (!$context) - $context = Context::getContext(); - return $context->link->getCategoryLink($this->id, $this->link_rewrite); + if (!$link) + $link = Context::getContext()->link; + return $link->getCategoryLink($this->id, $this->link_rewrite); } - public function getName($id_lang = NULL, Context $context = null) + public function getName($id_lang = NULL) { if (!$id_lang) { - if (!$context) - $context = Context::getContext(); - - if (isset($this->name[$context->language->id])) - $id_lang = $context->language->id; + if (isset($this->name[Context::getContext()->language->id])) + $id_lang = Context::getContext()->language->id; else $id_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); } @@ -780,10 +778,10 @@ class CategoryCore extends ObjectModel * @param integer $id_lang Language ID * @return array Corresponding categories */ - public function getParentsCategories($idLang = null, Context $context = null) + public function getParentsCategories($id_lang = null) { - //get idLang - $idLang = is_null($idLang) ? $context->language->id : $idLang; + if (is_null($id_lang)) + $id_lang = $context->language->id; $categories = null; $idCurrent = $this->id; @@ -792,7 +790,7 @@ class CategoryCore extends ObjectModel $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.*, cl.* FROM `'._DB_PREFIX_.'category` c - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$idLang.') + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.') WHERE c.`id_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0 '); diff --git a/classes/FrontController.php b/classes/FrontController.php index 6ae44eb53..8c24c46a1 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -32,10 +32,13 @@ class FrontControllerCore * @var Context */ protected $context; + + /* Deprecated shortcuts as of 1.5 - Use $context->var instead */ protected static $smarty; protected static $cookie; protected static $link; protected static $cart; + public $iso; public $orderBy; @@ -50,8 +53,8 @@ class FrontControllerCore protected $restrictedCountry = false; protected $maintenance = false; - protected $id_current_shop; - protected $id_current_group_shop; + protected $id_current_shop; + protected $id_current_group_shop; public static $initialized = false; @@ -535,8 +538,8 @@ class FrontControllerCore public function displayFooter() { - if (!self::$initialized) - $this->init(); + if (!$this->context) + $this->context = Context::getContext(); $this->context->smarty->assign(array( 'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)), diff --git a/classes/Product.php b/classes/Product.php index c5e78ecf2..8e31bf002 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2174,7 +2174,7 @@ class ProductCore extends ObjectModel FROM '._DB_PREFIX_.'stock WHERE id_product = '.$this->id.' AND id_product_attribute = '.(int)$id_product_attribute - .$context->shop->sqlSharedStock('', $context); + .$context->shop->sqlSharedStock(''); return (int)Db::getInstance()->getValue($sql); }