From 59bebb4f6c2e3ecce42d0369eb02635b74e8be69 Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 24 Feb 2012 10:11:29 +0000 Subject: [PATCH] // Fix shop context initialization in init.php git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13597 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/init.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/admin-dev/init.php b/admin-dev/init.php index efe822ee4..569070271 100644 --- a/admin-dev/init.php +++ b/admin-dev/init.php @@ -101,14 +101,38 @@ try $context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - $shopID = ''; + $shop_id = ''; + Shop::setContext(Shop::CONTEXT_ALL); if ($context->cookie->shopContext) { $split = explode('-', $context->cookie->shopContext); - if (count($split) == 2 && $split[0] == 's') - $shopID = (int)$split[1]; + if (count($split) == 2) + { + if ($split[0] == 'g') + Shop::setContext(Shop::CONTEXT_GROUP, $split[1]); + else + { + Shop::setContext(Shop::CONTEXT_SHOP, $split[1]); + $shop_id = $split[1]; + } + } } - $context->shop = new Shop($shopID); + else if ($context->employee->id_profile == _PS_ADMIN_PROFILE_) + $shop_id = ''; + else if ($context->shop->getTotalShopsWhoExists() != Employee::getTotalEmployeeShopById((int)$context->employee->id)) + { + $shops = Employee::getEmployeeShopById((int)$context->employee->id); + if (count($shops)) + $shop_id = (int)$shops[0]; + } + else + Employee::getEmployeeShopAccess((int)$context->employee->id); + + // Replace existing shop if necessary + if (!$shop_id) + $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT')); + else if ($context->shop->id != $shop_id) + $context->shop = new Shop($shop_id); } catch(PrestaShopException $e) {