// Refactoring of shop class with new context Part 2
This commit is contained in:
+22
-21
@@ -140,6 +140,8 @@ abstract class AdminTabCore
|
||||
|
||||
/** @var string specificConfirmDelete */
|
||||
public $specificConfirmDelete = NULL;
|
||||
|
||||
public $currentIndex = '';
|
||||
|
||||
protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms');
|
||||
|
||||
@@ -1692,21 +1694,22 @@ abstract class AdminTabCore
|
||||
*/
|
||||
public function displayOptionsList()
|
||||
{
|
||||
global $currentIndex, $cookie, $tab;
|
||||
global $tab;
|
||||
|
||||
$context = Context::getContext();
|
||||
if (!isset($this->_fieldsOptions) OR !sizeof($this->_fieldsOptions))
|
||||
return false;
|
||||
|
||||
$defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
$this->_languages = Language::getLanguages(false);
|
||||
$tab = Tab::getTab((int)$cookie->id_lang, Tab::getIdFromClassName($tab));
|
||||
$tab = Tab::getTab($context->language->id, Tab::getIdFromClassName($tab));
|
||||
echo '<br /><br />';
|
||||
echo (isset($this->optionTitle) ? '<h2>'.$this->optionTitle.'</h2>' : '');
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
id_language = Number('.$defaultLanguage.');
|
||||
</script>
|
||||
<form action="'.$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">
|
||||
<form action="'.$this->currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">
|
||||
<fieldset>';
|
||||
echo (isset($this->optionTitle) ? '<legend>
|
||||
<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />'
|
||||
@@ -1719,7 +1722,7 @@ abstract class AdminTabCore
|
||||
if (!Validate::isCleanHtml($val))
|
||||
$val = Configuration::get($key);
|
||||
|
||||
$isDisabled = (isset($field['visibility']) && $field['visibility'] > Shop::getContextType()) ? true : false;
|
||||
$isDisabled = (isset($field['visibility']) && $field['visibility'] > $context->shop->getContextType()) ? true : false;
|
||||
|
||||
echo $this->getHtmlDefaultConfigurationValue($key, $this->_languages);
|
||||
echo '<label>'.$field['title'].' </label>
|
||||
@@ -2002,8 +2005,6 @@ abstract class AdminTabCore
|
||||
|
||||
protected function warnDomainName()
|
||||
{
|
||||
global $currentIndex;
|
||||
|
||||
if ($_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN') AND $_SERVER['HTTP_HOST'] != Configuration::get('PS_SHOP_DOMAIN_SSL'))
|
||||
$this->displayWarning($this->l('Your are currently connected with the following domain name:').' <span style="color: #CC0000;">'.$_SERVER['HTTP_HOST'].'</span><br />'.
|
||||
$this->l('This one is different from the main shop domain name set in "Preferences > SEO & URLs":').' <span style="color: #CC0000;">'.Configuration::get('PS_SHOP_DOMAIN').'</span><br />
|
||||
@@ -2013,15 +2014,15 @@ abstract class AdminTabCore
|
||||
|
||||
protected function displayAssoShop($field_name = 'name')
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
if (!Tools::isMultiShopActivated() || (!$this->_object && Shop::getContextType() != Shop::CONTEXT_ALL))
|
||||
$context = Context::getContext();
|
||||
if (!Tools::isMultiShopActivated() || (!$this->_object && $context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
$shops = Shop::getShops();
|
||||
$objects = Db::getInstance()->ExecuteS('SELECT DISTINCT a.`'.pSQL($this->identifier).'`, '.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? 'b' : 'a').'.`'.pSQL($field_name).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'`a '.
|
||||
(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' LEFT JOIN `'._DB_PREFIX_.pSQL($this->table).'_lang` b ON (a.`'.pSQL($this->identifier).'`=b.`'.pSQL($this->identifier).'`)' : '').
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$cookie->id_lang : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : ''));
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$context->language->id : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : ''));
|
||||
$assos = array();
|
||||
$res = Db::getInstance()->ExecuteS('SELECT id_shop, `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_shop`');
|
||||
@@ -2032,7 +2033,7 @@ abstract class AdminTabCore
|
||||
{
|
||||
$html = '
|
||||
<table cellpadding="0" cellspacing="0" class="table">
|
||||
<form name="updateAssoShop" action="'.$currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
<form name="updateAssoShop" action="'.$this->currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
<input type="hidden" name="assoShopClass" value="'.$this->className.'" />
|
||||
<tr>
|
||||
<th style="width: 200px">'.$this->l('Shop association').'</th>';
|
||||
@@ -2074,15 +2075,14 @@ abstract class AdminTabCore
|
||||
|
||||
protected function displayAssoGroupShop($field_name = 'name')
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
|
||||
if (!Tools::isMultiShopActivated() || (!$this->_object && Shop::getContextType() != Shop::CONTEXT_ALL))
|
||||
$context = Context::getContext();
|
||||
if (!Tools::isMultiShopActivated() || (!$this->_object && $context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
$objects = Db::getInstance()->ExecuteS('SELECT DISTINCT a.`'.pSQL($this->identifier).'`, '.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? 'b' : 'a').'.`'.pSQL($field_name).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'` a'.
|
||||
(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' LEFT JOIN `'._DB_PREFIX_.pSQL($this->table).'_lang` b ON (a.`'.pSQL($this->identifier).'`=b.`'.pSQL($this->identifier).'`)' : '').
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$cookie->id_lang : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : ''));
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$context->language->id : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : ''));
|
||||
$groups_shop = GroupShop::getGroupShops();
|
||||
$assos = array();
|
||||
$res = Db::getInstance()->ExecuteS('SELECT id_group_shop, `'.pSQL($this->identifier).'`
|
||||
@@ -2091,7 +2091,7 @@ abstract class AdminTabCore
|
||||
$assos[$row['id_group_shop']][] = $row[$this->identifier];
|
||||
if (!$this->_object)
|
||||
{
|
||||
$html = '<form name="updateAssoGroupShop" action="'.$currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
$html = '<form name="updateAssoGroupShop" action="'.$this->currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
<input type="hidden" name="assoGroupShopClass" value="'.$this->className.'" />
|
||||
<table cellpadding="0" cellspacing="0" class="table">
|
||||
<tr>
|
||||
@@ -2157,21 +2157,22 @@ abstract class AdminTabCore
|
||||
*/
|
||||
protected function getHtmlDefaultConfigurationValue($key, $languages)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if (Configuration::isLangKey($key))
|
||||
{
|
||||
$testContext = false;
|
||||
foreach ($languages as $lang)
|
||||
if ((Shop::getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_SHOP))
|
||||
|| (Shop::getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_GROUP)))
|
||||
if (($context->shop->getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_SHOP))
|
||||
|| ($context->shop->getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_GROUP)))
|
||||
$testContext = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$testContext = ((Shop::getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, null, Shop::CONTEXT_SHOP))
|
||||
|| (Shop::getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false;
|
||||
$testContext = (($context->shop->getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, null, Shop::CONTEXT_SHOP))
|
||||
|| ($context->shop->getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false;
|
||||
}
|
||||
|
||||
if (Tools::isMultiShopActivated() && Shop::getContextType() != Shop::CONTEXT_ALL && $testContext)
|
||||
if (Tools::isMultiShopActivated() && $context->shop->getContextType() != Shop::CONTEXT_ALL && $testContext)
|
||||
{
|
||||
echo '<div class="multishop_config">';
|
||||
echo '<a href="#" title="'.$this->l('Click here to use default value for this field').'"><img src="../img/admin/multishop_config.png" /></a>';
|
||||
@@ -2192,7 +2193,7 @@ abstract class AdminTabCore
|
||||
$languages = Language::getLanguages(false);
|
||||
foreach ($fields as $key => $options)
|
||||
{
|
||||
if (isset($options['visibility']) && $options['visibility'] > Shop::getContextType())
|
||||
if (isset($options['visibility']) && $options['visibility'] > Context::getContext()->shop->getContextType())
|
||||
continue;
|
||||
|
||||
if (Tools::isMultiShopActivated() && isset($_POST['configUseDefault'][$key]))
|
||||
|
||||
@@ -579,9 +579,8 @@ class CategoryCore extends ObjectModel
|
||||
if (!$id_shop)
|
||||
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
|
||||
$shop = new Shop((int)$id_shop);
|
||||
$id_category = $shop->getRootCategory();
|
||||
|
||||
return new Category ((int)$id_category, is_null($id_lang) ? (int)_USER_ID_LANG_ : (int)($id_lang));
|
||||
return new Category ((int)$shop->id_category, is_null($id_lang) ? (int)_USER_ID_LANG_ : (int)($id_lang));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -372,7 +372,7 @@ class ConfigurationCore extends ObjectModel
|
||||
*/
|
||||
public static function deleteFromContext($key)
|
||||
{
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
if (!$shopID && !$shopGroupID)
|
||||
return;
|
||||
|
||||
@@ -395,7 +395,7 @@ class ConfigurationCore extends ObjectModel
|
||||
*/
|
||||
public static function hasContext($key, $langID, $context)
|
||||
{
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
if ($context == Shop::CONTEXT_SHOP && Configuration::hasKey($key, $langID, null, $shopID))
|
||||
return true;
|
||||
else if ($context == Shop::CONTEXT_GROUP && Configuration::hasKey($key, $langID, $shopGroupID))
|
||||
@@ -424,7 +424,7 @@ class ConfigurationCore extends ObjectModel
|
||||
*/
|
||||
protected static function getShopFromContext(&$id_group_shop, &$id_shop)
|
||||
{
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
if (is_null($id_shop))
|
||||
$id_shop = $shopID;
|
||||
if (is_null($id_group_shop))
|
||||
|
||||
@@ -188,7 +188,7 @@ class FrontControllerCore
|
||||
$cart->id_currency = (int)($cookie->id_currency);
|
||||
$cart->id_guest = (int)($cookie->id_guest);
|
||||
$cart->id_group_shop = (int)$this->id_current_group_shop;
|
||||
$cart->id_shop = (int)$this->id_current_shop;
|
||||
$cart->id_shop = $this->id_current_shop;
|
||||
if ($cookie->id_customer)
|
||||
{
|
||||
$cart->id_customer = (int)($cookie->id_customer);
|
||||
@@ -276,7 +276,7 @@ class FrontControllerCore
|
||||
'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
|
||||
'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
|
||||
'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE'),
|
||||
'id_current_shop' => (int)$this->id_current_shop,
|
||||
'id_current_shop' => $this->id_current_shop,
|
||||
'id_current_group_shop' => (int)$this->id_current_group_shop
|
||||
));
|
||||
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ abstract class ModuleCore
|
||||
public function __construct($name = null)
|
||||
{
|
||||
// Search the module shop context
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
$this->setShopID($shopID);
|
||||
$this->setShopGroupID($shopGroupID);
|
||||
|
||||
|
||||
@@ -124,12 +124,13 @@ abstract class ObjectModelCore
|
||||
/* Connect to database and check SQL table/identifier */
|
||||
if (!Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError());
|
||||
$db = Db::getInstance();
|
||||
$this->identifier = pSQL($this->identifier);
|
||||
/* Load object from database if object id is present */
|
||||
if ($id)
|
||||
{
|
||||
if (!isset(self::$_cache[$this->table][(int)$id][(int)$id_shop][(int)$id_lang]))
|
||||
self::$_cache[$this->table][(int)($id)][(int)$id_shop][(int)$id_lang] = Db::getInstance()->getRow('
|
||||
self::$_cache[$this->table][(int)($id)][(int)$id_shop][(int)$id_lang] = $db->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.$this->table.'` a '.
|
||||
($id_lang ? ('LEFT JOIN `'.pSQL(_DB_PREFIX_.$this->table).'_lang` b ON (a.`'.$this->identifier.'` = b.`'.$this->identifier).'` AND `id_lang` = '.(int)($id_lang).')' : '')
|
||||
@@ -145,7 +146,7 @@ abstract class ObjectModelCore
|
||||
|
||||
if (!$id_lang AND method_exists($this, 'getTranslationsFieldsChild'))
|
||||
{
|
||||
$result = Db::getInstance()->ExecuteS('SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang`
|
||||
$result = $db->ExecuteS('SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang`
|
||||
WHERE `'.$this->identifier.'` = '.(int)$id
|
||||
.(($this->langMultiShop AND $id_shop) ? ' AND `id_shop`='.(int)$id_shop : ''));
|
||||
if ($result)
|
||||
|
||||
+20
-12
@@ -2079,17 +2079,22 @@ class ProductCore extends ObjectModel
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $quantity
|
||||
* @param int $id_product_attribute
|
||||
* @param bool $update
|
||||
* @param Context $context
|
||||
*/
|
||||
public function setStock($quantity, $id_product_attribute = 0, $update = false)
|
||||
public function setStock($quantity, $id_product_attribute = 0, $update = false, $context = null)
|
||||
{
|
||||
if (!$this->id)
|
||||
return ;
|
||||
$shop = Context::getContext()->shop->getID();
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$shop = $context->shop;
|
||||
|
||||
// For retrocompatibility
|
||||
$id_product_attribute = (int)$id_product_attribute;
|
||||
$quantity = (int)$quantity;
|
||||
if (Shop::getInstance($shop)->isDefaultShop())
|
||||
if ($shop->isDefaultShop())
|
||||
{
|
||||
if ($id_product_attribute)
|
||||
{
|
||||
@@ -2111,7 +2116,7 @@ class ProductCore extends ObjectModel
|
||||
// Change stock quantity on product attribute
|
||||
if ($id_product_attribute)
|
||||
{
|
||||
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop))
|
||||
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID()))
|
||||
{
|
||||
$sql = 'UPDATE '._DB_PREFIX_.'stock
|
||||
SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).'
|
||||
@@ -2122,14 +2127,14 @@ class ProductCore extends ObjectModel
|
||||
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
|
||||
'id_product' => $this->id,
|
||||
'id_product_attribute' => $id_product_attribute,
|
||||
'id_shop' => $shop,
|
||||
'id_group_shop' => Shop::getGroupFromShop($shop),
|
||||
'id_shop' => $shop->getID(),
|
||||
'id_group_shop' => $shop->getGroupID(),
|
||||
'quantity' => $quantity,
|
||||
), 'INSERT');
|
||||
}
|
||||
|
||||
// Change stock quantity on product
|
||||
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop))
|
||||
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID()))
|
||||
{
|
||||
$sql = 'UPDATE '._DB_PREFIX_.'stock
|
||||
SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).'
|
||||
@@ -2140,8 +2145,8 @@ class ProductCore extends ObjectModel
|
||||
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
|
||||
'id_product' => $this->id,
|
||||
'id_product_attribute' => 0,
|
||||
'id_shop' => $shop,
|
||||
'id_group_shop' => Shop::getGroupFromShop($shop),
|
||||
'id_shop' => $shop->getID(),
|
||||
'id_group_shop' => $shop->getGroupID(),
|
||||
'quantity' => $quantity,
|
||||
), 'INSERT');
|
||||
}
|
||||
@@ -2150,19 +2155,22 @@ class ProductCore extends ObjectModel
|
||||
* Get the stock quantity of current product
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $id_product_attribute
|
||||
* @param Context $context
|
||||
* @return int
|
||||
*/
|
||||
public function getStock($id_product_attribute = 0)
|
||||
public function getStock($id_product_attribute = 0, $context = null)
|
||||
{
|
||||
if (!$this->id)
|
||||
return 0;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$shop = Context::getContext()->shop->getID();
|
||||
$sql = 'SELECT quantity
|
||||
FROM '._DB_PREFIX_.'stock
|
||||
WHERE id_product = '.$this->id.'
|
||||
AND id_product_attribute = '.(int)$id_product_attribute
|
||||
.Shop::sqlSharedStock('', $shop);
|
||||
.Shop::sqlSharedStock();
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
|
||||
+36
-35
@@ -45,12 +45,6 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
//private static $current_base_uri;
|
||||
//private static $current_theme_name;
|
||||
private static $id_current_shop;
|
||||
private static $id_current_group_shop;
|
||||
private static $id_current_root_category;
|
||||
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array(
|
||||
'active' => 'isBool',
|
||||
@@ -220,7 +214,7 @@ class ShopCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
$this->theme_name = $row['name'];
|
||||
$this->base_uri = $row['uri'];
|
||||
$this->base_uri = ($row['uri']) ? $row['uri'].'/' : '';
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -315,7 +309,17 @@ class ShopCore extends ObjectModel
|
||||
{
|
||||
return ($this->id == Configuration::get('PS_SHOP_DEFAULT'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of associated tables to shop
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssoTables()
|
||||
{
|
||||
return self::$assoTables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load list of groups and shops, and cache it
|
||||
*
|
||||
@@ -357,17 +361,7 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of associated tables to shop
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssoTables()
|
||||
{
|
||||
return self::$assoTables;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get shops list
|
||||
*
|
||||
@@ -390,7 +384,7 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a shop ID from shop name
|
||||
*
|
||||
@@ -406,7 +400,7 @@ class ShopCore extends ObjectModel
|
||||
return $shopID;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int Total of shops
|
||||
*/
|
||||
@@ -414,7 +408,7 @@ class ShopCore extends ObjectModel
|
||||
{
|
||||
return count(Shop::getShops($active));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve group ID of a shop
|
||||
*
|
||||
@@ -449,23 +443,24 @@ class ShopCore extends ObjectModel
|
||||
* Retrieve the current shop context in FO or BO
|
||||
*
|
||||
* @param string null|shop|group
|
||||
* @param bool If true, this method will return default shop ID if no shop was found in context (for BO)
|
||||
* @return array(id_shop, id_group_shop)|int
|
||||
*/
|
||||
public static function retrieveContext($type = null)
|
||||
public static function getContext($type = null, $useDefault = false)
|
||||
{
|
||||
static $executed = false, $shopID = 0, $shopGroupID = 0;
|
||||
|
||||
if (!$executed)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if (defined('PS_ADMIN_DIR'))
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
// While cookie is not instancied in admin, we wait ...
|
||||
if (!$cookie)
|
||||
if (!isset($context->cookie))
|
||||
return ($type == 'shop' || $type == 'group') ? '' : array('', '');
|
||||
|
||||
// Parse shopContext cookie value (E.g. s-2, g-4)
|
||||
$split = explode('-', $cookie->shopContext);
|
||||
$split = explode('-', Context::getContext()->cookie);
|
||||
$shopID = $shopGroupID = '';
|
||||
if (count($split) == 2)
|
||||
{
|
||||
@@ -480,11 +475,17 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
else
|
||||
{
|
||||
$shopID = (int)self::$id_current_shop;
|
||||
$shopGroupID = (int)self::$id_current_group_shop;
|
||||
$shopID = $context->shop->getID();
|
||||
$shopGroupID = $context->shop->getGroupID();
|
||||
}
|
||||
$executed = true;
|
||||
}
|
||||
|
||||
if ($useDefault && !$shopID)
|
||||
$shopID = Configuration::get('PS_SHOP_DEFAULT');
|
||||
if ($useDefault && !$shopGroupID)
|
||||
$shopID = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT'));
|
||||
|
||||
if ($type == 'shop')
|
||||
return $shopID;
|
||||
else if ($type == 'group')
|
||||
@@ -519,7 +520,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function getListFromContext()
|
||||
{
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
return Shop::getListOfID($shopID, $shopGroupID);
|
||||
}
|
||||
|
||||
@@ -528,9 +529,9 @@ class ShopCore extends ObjectModel
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getContextType()
|
||||
public function getContextType()
|
||||
{
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
if ($shopID)
|
||||
return Shop::CONTEXT_SHOP;
|
||||
else if ($shopGroupID)
|
||||
@@ -548,9 +549,9 @@ class ShopCore extends ObjectModel
|
||||
|
||||
$restriction = '';
|
||||
if (is_null($shopID))
|
||||
$shopID = Shop::retrieveContext('shop');
|
||||
$shopID = Shop::getContext('shop');
|
||||
if (is_null($shopGroupID))
|
||||
$shopGroupID = Shop::retrieveContext('group');
|
||||
$shopGroupID = Shop::getContext('group');
|
||||
|
||||
if ($type == 'group_shop')
|
||||
{
|
||||
@@ -607,7 +608,7 @@ class ShopCore extends ObjectModel
|
||||
$tree = Shop::getTree();
|
||||
|
||||
// Get default value
|
||||
list($shopID, $shopGroupID) = Shop::retrieveContext();
|
||||
list($shopID, $shopGroupID) = Shop::getContext();
|
||||
if ($shopID)
|
||||
$value = 's-'.$shopID;
|
||||
else if ($shopGroupID)
|
||||
|
||||
Reference in New Issue
Block a user