diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 02bc640cb..39bf09099 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -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) { diff --git a/classes/Currency.php b/classes/Currency.php index 300fda6b0..c8c55cf1e 100644 --- a/classes/Currency.php +++ b/classes/Currency.php @@ -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) diff --git a/classes/Hook.php b/classes/Hook.php index 5db195e5e..436b015fe 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -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(); diff --git a/classes/Module.php b/classes/Module.php index 8a1dae4f4..af83e1a6c 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -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; diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 03bd2343b..492626844 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -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; diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index c44755a12..f1161934c 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -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') { diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index d23895b5c..0487fa70b 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -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; } diff --git a/config/config.inc.php b/config/config.inc.php index f11768f5e..4989b13a7 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -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; diff --git a/controllers/admin/AdminAccountingManagementController.php b/controllers/admin/AdminAccountingManagementController.php index 7dbf6ed1f..07db34892 100644 --- a/controllers/admin/AdminAccountingManagementController.php +++ b/controllers/admin/AdminAccountingManagementController.php @@ -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 { diff --git a/controllers/admin/AdminInvoicesController.php b/controllers/admin/AdminInvoicesController.php index 83695db4c..b66148410 100644 --- a/controllers/admin/AdminInvoicesController.php +++ b/controllers/admin/AdminInvoicesController.php @@ -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 '); diff --git a/controllers/admin/AdminModulesPositionsController.php b/controllers/admin/AdminModulesPositionsController.php index 9323a2984..4f8e73e33 100644 --- a/controllers/admin/AdminModulesPositionsController.php +++ b/controllers/admin/AdminModulesPositionsController.php @@ -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); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 0cdbf2ad6..e7c4dce56 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -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 { diff --git a/controllers/admin/AdminReferrersController.php b/controllers/admin/AdminReferrersController.php index 27788612b..83b28bd86 100644 --- a/controllers/admin/AdminReferrersController.php +++ b/controllers/admin/AdminReferrersController.php @@ -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'; diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index 6630c76e9..70363193f 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -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)) {