diff --git a/admin-dev/init.php b/admin-dev/init.php index 61a63c83b..c36b09571 100644 --- a/admin-dev/init.php +++ b/admin-dev/init.php @@ -85,4 +85,12 @@ if (Shop::isMultiShopActivated() && Tools::getValue('setShopContext') !== false) $context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $context->country = $defaultCountry; -$context->shop = new Shop(Shop::getContextID()); \ No newline at end of file + +$shopID = ''; +if ($context->cookie->shopContext) +{ + $split = explode('-', $context->cookie->shopContext); + if (count($split) == 2 && $split[0] == 's') + $shopID = (int)$split[1]; +} +$context->shop = new Shop($shopID); \ No newline at end of file diff --git a/admin-dev/tabs/AdminModules.php b/admin-dev/tabs/AdminModules.php index 11331c79b..06ec4e213 100644 --- a/admin-dev/tabs/AdminModules.php +++ b/admin-dev/tabs/AdminModules.php @@ -288,6 +288,14 @@ class AdminModules extends AdminTab $this->_errors[] = Tools::displayError('This module is already uninstalled:').' '.$module->name; else { + // If we install a module, force temporary global context for multishop + if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL) + { + Context::getContext()->tmpOldShop = clone(Context::getContext()->shop); + Context::getContext()->shop = new Shop(); + Configuration::updateValue('RSS_FEED_TITLE', 'lol'); + } + if (((method_exists($module, $method) && ($echo = $module->{$method}())) || ($echo = ' ')) AND $key == 'configure' AND Module::isInstalled($module->name)) { $backlink = self::$currentIndex.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name; @@ -335,6 +343,12 @@ class AdminModules extends AdminTab $return = ($method == 'install' ? 12 : 13); elseif ($echo === false) $module_errors[] = $name; + + if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && isset(Context::getContext()->tmpOldShop)) + { + Context::getContext()->shop = clone(Context::getContext()->tmpOldShop); + unset(Context::getContext()->tmpOldShop); + } } if ($key != 'configure' AND isset($_GET['bpay'])) Tools::redirectAdmin('index.php?tab=AdminPayment&token='.Tools::getAdminToken('AdminPayment'.(int)(Tab::getIdFromClassName('AdminPayment')).(int)$this->context->employee->id)); diff --git a/classes/Shop.php b/classes/Shop.php index 35b6cd45b..d6ff3b225 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -535,7 +535,28 @@ class ShopCore extends ObjectModel */ public static function getContext($type = null) { - static $executed = false, $shopID = 0, $shopGroupID = 0; + $context = Context::getContext(); + if (!isset($context->shop)) + return ($type == 'shop' || $type == 'group') ? '' : array('', ''); + + $shopID = $context->shop->id; + $shopGroupID = $context->shop->id_group_shop; + if (defined('PS_ADMIN_DIR')) + { + if (!isset($context->cookie) || !$context->cookie->shopContext) + return ($type == 'shop' || $type == 'group') ? '' : array('', ''); + + // Parse shopContext cookie value (E.g. s-2, g-4) + $split = explode('-', $context->cookie->shopContext); + if (count($split) == 2 && $split[0] == 'g') + $shopGroupID = (int)$split[1]; + } + + if ($type == 'shop') + return $shopID; + else if ($type == 'group') + return $shopGroupID; + return array($shopID, $shopGroupID); if (!$executed) { @@ -547,7 +568,7 @@ class ShopCore extends ObjectModel return ($type == 'shop' || $type == 'group') ? '' : array('', ''); // Parse shopContext cookie value (E.g. s-2, g-4) - $split = explode('-', Context::getContext()->cookie->shopContext); + $split = explode('-', $context->cookie->shopContext); if (count($split) == 2) { if ($split[0] == 's') @@ -561,8 +582,7 @@ class ShopCore extends ObjectModel } else { - if (!isset($context->shop)) - return ($type == 'shop' || $type == 'group') ? '' : array('', ''); + $shopID = (int)$context->shop->getID(); $shopGroupID = (int)$context->shop->id_group_shop; }