// Context part 21

This commit is contained in:
tDidierjean
2011-07-26 16:40:17 +00:00
parent a64edf3ff6
commit ea890721e8
7 changed files with 62 additions and 63 deletions
+1 -1
View File
@@ -121,7 +121,7 @@ class AttributeCore extends ObjectModel
static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null) static public function checkAttributeQty($id_product_attribute, $qty, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
$$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
$sql = 'SELECT quantity $sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock FROM '._DB_PREFIX_.'stock
+4 -5
View File
@@ -104,11 +104,10 @@ class CMSCore extends ObjectModel
return false; 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) if (!$link)
$context = Context::getContext(); $link = Context::getContext()->link;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_cms, cl.link_rewrite, cl.meta_title SELECT c.id_cms, cl.link_rewrite, cl.meta_title
FROM '._DB_PREFIX_.'cms c FROM '._DB_PREFIX_.'cms c
@@ -122,7 +121,7 @@ class CMSCore extends ObjectModel
if ($result) if ($result)
foreach ($result as $row) 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; $links[] = $row;
} }
return $links; return $links;
+21 -22
View File
@@ -145,31 +145,32 @@ class CMSCategoryCore extends ObjectModel
* *
* @return array Subcategories lite tree * @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) if (!$link)
$context = Context::getContext(); $link = Context::getContext()->link;
//get idLang
$idLang = is_null($idLang) ? $context->language->id : (int)($idLang); if (is_null($id_lang))
$id_lang = Context::getContext()->language->id;
//recursivity for subcategories //recursivity for subcategories
$children = array(); $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) foreach ($subcats as &$subcat)
{ {
if (!$subcat['id_cms_category']) if (!$subcat['id_cms_category'])
break; break;
elseif ( !is_array($excludedIdsArray) || !in_array($subcat['id_cms_category'], $excludedIdsArray) ) 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); $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( return array(
'id' => $this->id_cms_category, '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, 'name' => $this->name,
'desc'=> $this->description, 'desc'=> $this->description,
'children' => $children 'children' => $children
@@ -467,19 +468,19 @@ class CMSCategoryCore extends ObjectModel
return $result['link_rewrite']; return $result['link_rewrite'];
} }
public function getLink(Context $context = null) public function getLink(Link $link = null)
{ {
if (!$context) if (!$link)
$context = Context::getContext(); $link = Context::getContext()->link;
return $context->link->getCMSCategoryLink($this->id, $this->link_rewrite); 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 (!$id_lang)
{ {
if (isset($this->name[$context->language->id])) if (isset($this->name[Context::getContext()->language->id]))
$id_lang = $context->language->id; $id_lang = Context::getContext()->language->id;
else else
$id_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); $id_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
} }
@@ -537,12 +538,10 @@ class CMSCategoryCore extends ObjectModel
* @param integer $id_lang Language ID * @param integer $id_lang Language ID
* @return array Corresponding categories * @return array Corresponding categories
*/ */
public function getParentsCategories($idLang = null, Context $context = null) public function getParentsCategories($id_lang = null)
{ {
if (!$context) if (is_null($id_lang))
$context = Context::getContext(); $id_lang = Context::getContext()->language->id;
//get idLang
$idLang = is_null($idLang) ? $context->language->id : $idLang;
$categories = null; $categories = null;
$idCurrent = $this->id; $idCurrent = $this->id;
@@ -551,7 +550,7 @@ class CMSCategoryCore extends ObjectModel
$query = ' $query = '
SELECT c.*, cl.* SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'cms_category` c 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 WHERE c.`id_cms_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0
'; ';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query);
+2 -2
View File
@@ -620,7 +620,7 @@ class CartCore extends ObjectModel
{ {
$sql = 'SELECT p.out_of_stock, stock.quantity $sql = 'SELECT p.out_of_stock, stock.quantity
FROM '._DB_PREFIX_.'product p 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; WHERE p.id_product = '.$id_product;
$result2 = Db::getInstance()->getRow($sql); $result2 = Db::getInstance()->getRow($sql);
if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock'])) if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock']))
@@ -634,7 +634,7 @@ class CartCore extends ObjectModel
'id_product' => (int)$id_product, 'id_product' => (int)$id_product,
'id_product_attribute' => (int)$id_product_attribute, 'id_product_attribute' => (int)$id_product_attribute,
'id_cart' => (int)$this->id, 'id_cart' => (int)$this->id,
'id_shop' => $context->shop->getID(true), 'id_shop' => $shop->getID(true),
'quantity' => (int)$quantity, 'quantity' => (int)$quantity,
'date_add' => date('Y-m-d H:i:s') 'date_add' => date('Y-m-d H:i:s')
), 'INSERT'); ), 'INSERT');
+26 -28
View File
@@ -184,33 +184,32 @@ class CategoryCore extends ObjectModel
* *
* @param integer $maxDepth Maximum depth of the tree (i.e. 2 => 3 levels depth) * @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 $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 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 * @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) $id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang;
$context = Context::getContext();
$idLang = is_null($idLang) ? $context->language->id : (int)$idLang;
$children = array(); $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) foreach ($subcats AS &$subcat)
{ {
if (!$subcat['id_category']) if (!$subcat['id_category'])
break; break;
elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray)) elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray))
{ {
$categ = new Category((int)$subcat['id_category'], $idLang); $categ = new Category((int)$subcat['id_category'], $id_lang);
$children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray); $children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray);
} }
} }
return array( return array(
'id' => (int)$this->id_category, '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, 'name' => $this->name,
'desc'=> $this->description, 'desc'=> $this->description,
'children' => $children '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` 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) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)
'.$context->shop->sqlAsso('product', 'p').' '.$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_.'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_.'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) 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); 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) if (is_null($id_lang))
$context = Context::getContext(); $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']; return $result['link_rewrite'];
} }
public function getLink(Context $context = null) public function getLink(Link $link = null)
{ {
if (!$context) if (!$link)
$context = Context::getContext(); $link = Context::getContext()->link;
return $context->link->getCategoryLink($this->id, $this->link_rewrite); 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 (!$id_lang)
{ {
if (!$context) if (isset($this->name[Context::getContext()->language->id]))
$context = Context::getContext(); $id_lang = Context::getContext()->language->id;
if (isset($this->name[$context->language->id]))
$id_lang = $context->language->id;
else else
$id_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); $id_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
} }
@@ -780,10 +778,10 @@ class CategoryCore extends ObjectModel
* @param integer $id_lang Language ID * @param integer $id_lang Language ID
* @return array Corresponding categories * @return array Corresponding categories
*/ */
public function getParentsCategories($idLang = null, Context $context = null) public function getParentsCategories($id_lang = null)
{ {
//get idLang if (is_null($id_lang))
$idLang = is_null($idLang) ? $context->language->id : $idLang; $id_lang = $context->language->id;
$categories = null; $categories = null;
$idCurrent = $this->id; $idCurrent = $this->id;
@@ -792,7 +790,7 @@ class CategoryCore extends ObjectModel
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.*, cl.* SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'category` c 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 WHERE c.`id_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0
'); ');
+7 -4
View File
@@ -32,10 +32,13 @@ class FrontControllerCore
* @var Context * @var Context
*/ */
protected $context; protected $context;
/* Deprecated shortcuts as of 1.5 - Use $context->var instead */
protected static $smarty; protected static $smarty;
protected static $cookie; protected static $cookie;
protected static $link; protected static $link;
protected static $cart; protected static $cart;
public $iso; public $iso;
public $orderBy; public $orderBy;
@@ -50,8 +53,8 @@ class FrontControllerCore
protected $restrictedCountry = false; protected $restrictedCountry = false;
protected $maintenance = false; protected $maintenance = false;
protected $id_current_shop; protected $id_current_shop;
protected $id_current_group_shop; protected $id_current_group_shop;
public static $initialized = false; public static $initialized = false;
@@ -535,8 +538,8 @@ class FrontControllerCore
public function displayFooter() public function displayFooter()
{ {
if (!self::$initialized) if (!$this->context)
$this->init(); $this->context = Context::getContext();
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)), 'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),
+1 -1
View File
@@ -2174,7 +2174,7 @@ class ProductCore extends ObjectModel
FROM '._DB_PREFIX_.'stock FROM '._DB_PREFIX_.'stock
WHERE id_product = '.$this->id.' WHERE id_product = '.$this->id.'
AND id_product_attribute = '.(int)$id_product_attribute AND id_product_attribute = '.(int)$id_product_attribute
.$context->shop->sqlSharedStock('', $context); .$context->shop->sqlSharedStock('');
return (int)Db::getInstance()->getValue($sql); return (int)Db::getInstance()->getValue($sql);
} }