// Improve multishop_context in AdminController and rename shop->getListOfID() by Shop::getContextListShopID()

This commit is contained in:
rMalie
2012-02-27 09:49:19 +00:00
parent e689b06f2c
commit 20f2f2de7d
14 changed files with 59 additions and 44 deletions
+1 -1
View File
@@ -1313,7 +1313,7 @@ abstract class AdminTabCore
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
{
$filterKey = $assos[$this->table]['type'];
$idenfierShop = $this->context->shop->getListOfID();
$idenfierShop = Shop::getContextListShopID();
}
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
{
+1
View File
@@ -205,6 +205,7 @@ class CurrencyCore extends ObjectModel
'.$shop->addSqlAssociation('currency', 'c').'
WHERE `deleted` = 0'
.($active == 1 ? ' AND c.`active` = 1' : '').'
GROUP BY c.id_currency
ORDER BY `name` ASC';
$tab = Db::getInstance()->executeS($sql);
if ($object)
+2 -2
View File
@@ -177,7 +177,7 @@ class HookCore extends ObjectModel
FROM `'._DB_PREFIX_.'hook` h
INNER JOIN `'._DB_PREFIX_.'hook_module` hm ON (h.id_hook = hm.id_hook)
INNER JOIN `'._DB_PREFIX_.'module` as m ON (m.id_module = hm.id_module)
WHERE hm.id_shop IN('.implode(', ', Context::getContext()->shop->getListOfID()).')
WHERE hm.id_shop IN('.implode(', ', Shop::getContextListShopID()).')
GROUP BY hm.id_hook, hm.id_module
ORDER BY hm.position';
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
@@ -240,7 +240,7 @@ class HookCore extends ObjectModel
if (!Cache::isStored($cache_id))
{
// Get shops and groups list
$shop_list = $context->shop->getListOfID();
$shop_list = Shop::getContextListShopID();
if (isset($context->customer) && $context->customer->isLogged())
$groups = $context->customer->getGroups();
+11 -11
View File
@@ -142,7 +142,7 @@ abstract class ModuleCore
if (self::$modules_cache == null && !is_array(self::$modules_cache))
{
// Join clause is done to check if the module is activated in current shop context
$list = $this->context->shop->getListOfID();
$list = Shop::getContextListShopID();
$sql_limit_shop = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` IN ('.implode(',', $list).')';
$sql = 'SELECT m.`id_module`, m.`name`, ('.$sql_limit_shop.') as total FROM `'._DB_PREFIX_.'module` m';
@@ -532,7 +532,7 @@ abstract class ModuleCore
public function enable($forceAll = false)
{
// Retrieve all shops where the module is enabled
$list = $this->context->shop->getListOfID();
$list = Shop::getContextListShopID();
$sql = 'SELECT `id_shop` FROM `'._DB_PREFIX_.'module_shop` WHERE `id_module` = '.$this->id.' '.((!$forceAll) ? 'AND `id_shop` IN('.implode(', ', $list).')' : '');
// Store the results in an array
@@ -581,7 +581,7 @@ abstract class ModuleCore
public function disable($forceAll = false)
{
// Disable module for all shops
$sql = 'DELETE FROM `'._DB_PREFIX_.'module_shop` WHERE `id_module` = '.$this->id.' '.((!$forceAll) ? ' AND `id_shop` IN('.implode(', ', $this->context->shop->getListOfID()).')' : '');
$sql = 'DELETE FROM `'._DB_PREFIX_.'module_shop` WHERE `id_module` = '.$this->id.' '.((!$forceAll) ? ' AND `id_shop` IN('.implode(', ', Shop::getContextListShopID()).')' : '');
Db::getInstance()->execute($sql);
}
@@ -743,7 +743,7 @@ abstract class ModuleCore
{
// If shop lists is null, we fill it with all shops
if (is_null($shop_list))
Context::getContext()->shop->getListOfID();
$shop_list = Shop::getContextListShopID();
// Save modules exception for each shop
foreach ($shop_list as $shop_id)
@@ -778,7 +778,7 @@ abstract class ModuleCore
$result = true;
foreach ($excepts as $shop_id => $except)
{
$shop_list = ($shop_id == 0) ? Context::getContext()->shop->getListOfID() : array($shop_id);
$shop_list = ($shop_id == 0) ? Shop::getContextListShopID() : array($shop_id);
$this->unregisterExceptions($id_hook, $shop_list);
$result &= $this->registerExceptions($id_hook, $except, $shop_list);
}
@@ -1050,7 +1050,7 @@ abstract class ModuleCore
// Get modules information from database
if (!empty($module_name_list))
{
$list = Context::getContext()->shop->getListOfID();
$list = Shop::getContextListShopID();
$sql = 'SELECT m.id_module, m.name, (
SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE m.id_module = ms.id_module AND ms.id_shop IN ('.implode(',', $list).')
@@ -1239,7 +1239,7 @@ abstract class ModuleCore
if (Db::getInstance()->getValue('SELECT `id_hook` FROM `'._DB_PREFIX_.'hook` WHERE `name` = \'displayPayment\''))
$hookPayment = 'displayPayment';
$list = Context::getContext()->shop->getListOfID();
$list = Shop::getContextListShopID();
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
FROM `'._DB_PREFIX_.'module_country` mc
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
@@ -1297,7 +1297,7 @@ abstract class ModuleCore
*/
public function updatePosition($id_hook, $way, $position = null)
{
foreach ($this->context->shop->getListOfID() as $shop_id)
foreach (Shop::getContextListShopID() as $shop_id)
{
$sql = 'SELECT hm.`id_module`, hm.`position`, hm.`id_hook`
FROM `'._DB_PREFIX_.'hook_module` hm
@@ -1399,7 +1399,7 @@ abstract class ModuleCore
{
self::$exceptionsCache = array();
$sql = 'SELECT * FROM `'._DB_PREFIX_.'hook_module_exceptions`
WHERE `id_shop` IN ('.implode(', ', Context::getContext()->shop->getListOfID()).')';
WHERE `id_shop` IN ('.implode(', ', Shop::getContextListShopID()).')';
$result = Db::getInstance()->executeS($sql);
foreach ($result as $row)
{
@@ -1418,7 +1418,7 @@ abstract class ModuleCore
if (!$dispatch)
{
$files = array();
foreach (Context::getContext()->shop->getListOfID() as $shop_id)
foreach (Shop::getContextListShopID() as $shop_id)
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id]))
foreach (self::$exceptionsCache[$key][$shop_id] as $file)
if (!in_array($file, $files))
@@ -1428,7 +1428,7 @@ abstract class ModuleCore
else
{
$list = array();
foreach (Context::getContext()->shop->getListOfID() as $shop_id)
foreach (Shop::getContextListShopID() as $shop_id)
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id]))
$list[$shop_id] = self::$exceptionsCache[$key][$shop_id];
return $list;
+1 -1
View File
@@ -478,7 +478,7 @@ abstract class ObjectModelCore
// If this table is linked to multishop system, update / insert for all shops from context
if ($this->isLangMultishop())
{
$list_shops = ($this->id_shop && !$this->get_shop_from_context) ? array($this->id_shop) : Context::getContext()->shop->getListOfID();
$list_shops = ($this->id_shop && !$this->get_shop_from_context) ? array($this->id_shop) : Shop::getContextListShopID();
foreach ($list_shops as $shop)
{
$field['id_shop'] = $shop;
+28 -14
View File
@@ -1645,6 +1645,24 @@ class AdminControllerCore extends Controller
$this->lite_display = true;
}
$this->initShopContext();
if ($this->ajax && method_exists($this, 'ajaxPreprocess'))
$this->ajaxPreProcess();
$this->context->smarty->assign(array(
'table' => $this->table,
'current' => self::$currentIndex,
'token' => $this->token,
));
$this->context->smarty->assign('submit_form_ajax', (int)Tools::getValue('submitFormAjax'));
$this->initProcess();
}
public function initShopContext()
{
// Change shop context ?
if (Shop::isFeatureActive() && Tools::getValue('setShopContext') !== false)
{
@@ -1685,24 +1703,20 @@ class AdminControllerCore extends Controller
else
Employee::getEmployeeShopAccess((int)$this->context->employee->id);
// Check multishop context and set right context if need
if (!($this->multishop_context & Shop::getContext()))
{
if (Shop::getContext() == Shop::CONTEXT_SHOP && !($this->multishop_context & Shop::CONTEXT_SHOP))
Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextGroupShopID());
if (Shop::getContext() == Shop::CONTEXT_GROUP && !($this->multishop_context & Shop::CONTEXT_GROUP))
Shop::setContext(Shop::CONTEXT_ALL);
}
// Replace existing shop if necessary
if (!$shop_id)
$this->context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
else if ($this->context->shop->id != $shop_id)
$this->context->shop = new Shop($shop_id);
if ($this->ajax && method_exists($this, 'ajaxPreprocess'))
$this->ajaxPreProcess();
$this->context->smarty->assign(array(
'table' => $this->table,
'current' => self::$currentIndex,
'token' => $this->token,
));
$this->context->smarty->assign('submit_form_ajax', (int)Tools::getValue('submitFormAjax'));
$this->initProcess();
}
/**
@@ -1950,7 +1964,7 @@ class AdminControllerCore extends Controller
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
{
$filter_key = $assos[$this->table]['type'];
$idenfier_shop = $this->context->shop->getListOfID();
$idenfier_shop = Shop::getContextListShopID();
}
else if (isset($assos_group[$this->table]) && $assos_group[$this->table]['type'] == 'group_shop')
{
+3 -3
View File
@@ -617,7 +617,7 @@ class ShopCore extends ObjectModel
* @param string $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
* @return array
*/
public function getListOfID($share = false)
public static function getContextListShopID($share = false)
{
if (Shop::getContext() == Shop::CONTEXT_SHOP)
$list = ($share) ? Shop::getSharedShops(Shop::getContextShopID(), $share) : array(Shop::getContextShopID());
@@ -713,7 +713,7 @@ class ShopCore extends ObjectModel
else
{
if (Shop::getContext() != Shop::CONTEXT_ALL)
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') ';
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getContextListShopID($share)).') ';
//else if ($share == Shop::SHARE_STOCK)
// $restriction = ' AND '.$alias.'id_shop = '.$this->getID(true);
}
@@ -742,7 +742,7 @@ class ShopCore extends ObjectModel
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
AND '.$table_alias.'.id_shop IN('.implode(', ', $this->getListOfID()).') ';
AND '.$table_alias.'.id_shop IN('.implode(', ', Shop::getContextListShopID()).') ';
return $sql;
}
+1 -1
View File
@@ -136,7 +136,7 @@ else
if (!isset($cookie->id_cart))
{
$shops_share = Context::getContext()->shop->getListOfID(Shop::SHARE_ORDER);
$shops_share = Shop::getContextListShopID(Shop::SHARE_ORDER);
$id_cart = Db::getInstance()->getValue('SELECT `id_cart` FROM `'._DB_PREFIX_.'cart` WHERE `id_customer` = "'.(int)$customer->id.'" AND `id_shop` IN ("'.implode('","', $shops_share).'") ORDER BY `id_cart` DESC');
if ($id_cart != false)
$cookie->id_cart = $id_cart;
@@ -39,7 +39,7 @@ class AdminAccountingManagementControllerCore extends AdminController
$shop = array();
$error = '';
if (count($this->context->shop->getListOfID()) > 1)
if (count(Shop::getContextListShopID()) > 1)
$error = $this->l('Please select the shop you want to configure');
else
{
@@ -158,7 +158,7 @@ class AdminInvoicesControllerCore extends AdminController
) id_order_state
FROM '._DB_PREFIX_.'order_invoice oi
LEFT JOIN '._DB_PREFIX_.'orders o ON (oi.id_order = o.id_order)
WHERE o.id_shop IN('.implode(', ', $this->context->shop->getListOfID()).')
WHERE o.id_shop IN('.implode(', ', Shop::getContextListShopID()).')
GROUP BY id_order_state
');
@@ -77,7 +77,7 @@ class AdminModulesPositionsControllerCore extends AdminController
// Adding vars...
else
{
if (!$module->registerHook($hook->name, Context::getContext()->shop->getListOfID()))
if (!$module->registerHook($hook->name, Shop::getContextListShopID()))
$this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
else
{
@@ -89,7 +89,7 @@ class AdminModulesPositionsControllerCore extends AdminController
if (!Validate::isFileName($except))
$this->errors[] = Tools::displayError('No valid value for field exceptions');
if (!$this->errors && !$module->registerExceptions($id_hook, $exceptions, Context::getContext()->shop->getListOfID()))
if (!$this->errors && !$module->registerExceptions($id_hook, $exceptions, Shop::getContextListShopID()))
$this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
}
@@ -150,7 +150,7 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->errors[] = Tools::displayError('No valid value for field exceptions');
// Add files exceptions
if (!$module->editExceptions($id_hook, $exceptions, Context::getContext()->shop->getListOfID()))
if (!$module->editExceptions($id_hook, $exceptions, Shop::getContextListShopID()))
$this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
else
Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
@@ -176,8 +176,8 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->errors[] = Tools::displayError('Hook cannot be loaded.');
else
{
if (!$module->unregisterHook($id_hook, Context::getContext()->shop->getListOfID())
|| !$module->unregisterExceptions($id_hook, Context::getContext()->shop->getListOfID()))
if (!$module->unregisterHook($id_hook, Shop::getContextListShopID())
|| !$module->unregisterExceptions($id_hook, Shop::getContextListShopID()))
$this->errors[] = Tools::displayError('An error occurred while deleting module from hook.');
else
Tools::redirectAdmin(self::$currentIndex.'&conf=17'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
@@ -309,7 +309,7 @@ class AdminModulesPositionsControllerCore extends AdminController
FROM '._DB_PREFIX_.'hook_module
WHERE id_module = '.$id_module.'
AND id_hook = '.$id_hook.'
AND id_shop IN('.implode(', ', Context::getContext()->shop->getListOfID()).')';
AND id_shop IN('.implode(', ', Shop::getContextListShopID()).')';
if (!Db::getInstance()->getValue($sql))
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
@@ -2468,7 +2468,7 @@ class AdminProductsControllerCore extends AdminController
$error = '';
$detail = array();
if (count($this->context->shop->getListOfID()) > 1)
if (count(Shop::getContextListShopID()) > 1)
$error = $this->l('Please select the shop you want to configure');
else
{
@@ -166,7 +166,7 @@ class AdminReferrersControllerCore extends AdminController
(sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'referrer_shop` sa
ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $this->context->shop->getListOfID()).'))';
ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', Shop::getContextListShopID()).'))';
$this->_group = 'GROUP BY sa.id_referrer';
@@ -130,7 +130,7 @@ class StatsBestCategories extends ModuleGrid
WHERE c.id_category IN (
SELECT s.id_category
FROM '._DB_PREFIX_.'shop s
WHERE s.id_shop IN ('.implode(', ', $this->context->shop->getListOfID()).')
WHERE s.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
)';
if ($result = Db::getInstance()->executeS($sql))
{