From 4e0723b3ccfbf4ad3853d8bfeee0fbfc88642cc5 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 12 Jul 2013 16:28:47 +0200 Subject: [PATCH] [-] BO : fixed charts and grids in multishop #PSCFV-8978 --- admin-dev/drawer.php | 47 ++++++++++++++++++++++++++++++++++++++++++-- admin-dev/grider.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/admin-dev/drawer.php b/admin-dev/drawer.php index c52ea4547..22baa705c 100644 --- a/admin-dev/drawer.php +++ b/admin-dev/drawer.php @@ -37,7 +37,6 @@ $height = Tools::getValue('height'); $id_employee = Tools::getValue('id_employee'); $id_lang = Tools::getValue('id_lang'); - if (!isset($cookie->id_employee) || !$cookie->id_employee || $cookie->id_employee != $id_employee) die(Tools::displayError()); @@ -47,6 +46,51 @@ if (!Validate::isModuleName($module)) if (!Tools::file_exists_cache($module_path = dirname(__FILE__).'/../modules/'.$module.'/'.$module.'.php')) die(Tools::displayError()); +$shop_id = ''; +Shop::setContext(Shop::CONTEXT_ALL); +if (Context::getContext()->cookie->shopContext) +{ + $split = explode('-', Context::getContext()->cookie->shopContext); + if (count($split) == 2) + { + if ($split[0] == 'g') + { + if (Context::getContext()->employee->hasAuthOnShopGroup($split[1])) + Shop::setContext(Shop::CONTEXT_GROUP, $split[1]); + else + { + $shop_id = Context::getContext()->employee->getDefaultShopID(); + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + } + else if (Shop::getShop($split[1]) && Context::getContext()->employee->hasAuthOnShop($split[1])) + { + $shop_id = $split[1]; + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + else + { + $shop_id = Context::getContext()->employee->getDefaultShopID(); + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + } +} + +// Check multishop context and set right context if need +if (Shop::getContext()) +{ + if (Shop::getContext() == Shop::CONTEXT_SHOP && !Shop::CONTEXT_SHOP) + Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextShopGroupID()); + if (Shop::getContext() == Shop::CONTEXT_GROUP && !Shop::CONTEXT_GROUP) + Shop::setContext(Shop::CONTEXT_ALL); +} + +// Replace existing shop if necessary +if (!$shop_id) + Context::getContext()->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT')); +elseif (Context::getContext()->shop->id != $shop_id) + Context::getContext()->shop = new Shop($shop_id); + require_once($module_path); $graph = new $module(); @@ -57,4 +101,3 @@ if ($option) $graph->create($render, $type, $width, $height, $layers); $graph->draw(); - diff --git a/admin-dev/grider.php b/admin-dev/grider.php index 6e97baf68..a8506a94d 100644 --- a/admin-dev/grider.php +++ b/admin-dev/grider.php @@ -50,6 +50,53 @@ if (!Validate::isModuleName($module)) if (!Tools::file_exists_cache($module_path = dirname(__FILE__).'/../modules/'.$module.'/'.$module.'.php')) die(Tools::displayError()); + +$shop_id = ''; +Shop::setContext(Shop::CONTEXT_ALL); +if (Context::getContext()->cookie->shopContext) +{ + $split = explode('-', Context::getContext()->cookie->shopContext); + if (count($split) == 2) + { + if ($split[0] == 'g') + { + if (Context::getContext()->employee->hasAuthOnShopGroup($split[1])) + Shop::setContext(Shop::CONTEXT_GROUP, $split[1]); + else + { + $shop_id = Context::getContext()->employee->getDefaultShopID(); + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + } + else if (Shop::getShop($split[1]) && Context::getContext()->employee->hasAuthOnShop($split[1])) + { + $shop_id = $split[1]; + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + else + { + $shop_id = Context::getContext()->employee->getDefaultShopID(); + Shop::setContext(Shop::CONTEXT_SHOP, $shop_id); + } + } +} + +// Check multishop context and set right context if need +if (Shop::getContext()) +{ + if (Shop::getContext() == Shop::CONTEXT_SHOP && !Shop::CONTEXT_SHOP) + Shop::setContext(Shop::CONTEXT_GROUP, Shop::getContextShopGroupID()); + if (Shop::getContext() == Shop::CONTEXT_GROUP && !Shop::CONTEXT_GROUP) + Shop::setContext(Shop::CONTEXT_ALL); +} + +// Replace existing shop if necessary +if (!$shop_id) + Context::getContext()->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT')); +elseif (Context::getContext()->shop->id != $shop_id) + Context::getContext()->shop = new Shop($shop_id); + + require_once($module_path); $grid = new $module();