From 201c193dd48610f7ff1d25d07c8952f69b3199ff Mon Sep 17 00:00:00 2001 From: vChabot Date: Tue, 10 Jan 2012 10:29:53 +0000 Subject: [PATCH] // little fix about categories with multishop and Helper::renderAdminCategorieTree git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12301 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Category.php | 2 +- controllers/admin/AdminCategoriesController.php | 15 +++++++++++++-- controllers/admin/AdminProductsController.php | 10 ++++++++-- controllers/admin/AdminScenesController.php | 9 ++++++++- controllers/admin/AdminShopController.php | 3 ++- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/classes/Category.php b/classes/Category.php index 3a806eae3..91f2e4509 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -1292,7 +1292,7 @@ class CategoryCore extends ObjectModel public static function getCategoriesWithoutParent() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT c.* + SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') WHERE `id_parent` = 0 diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index fd9d54413..9c11fa685 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -116,12 +116,17 @@ class AdminCategoriesControllerCore extends AdminController $id_parent = $this->_category->id; else if ($nb_shop == 1 && $count_categories_without_parent > 1) $id_parent = 0; + else if ($nb_shop > 1 && $count_categories_without_parent == 1) + $id_parent = 1; + else if ($nb_shop > 1 && $count_categories_without_parent > 1 && $this->context->shop() != Shop::CONTEXT_SHOP) + $id_parent = 0; else $id_parent = $this->context->shop->id_category; + $this->_filter .= ' AND `id_parent` = '.(int)$id_parent.' '; $this->_select = 'position '; // we add restriction for shop - if (Shop::CONTEXT_ALL == Context::getContext()->shop()) + if (Shop::CONTEXT_SHOP == Context::getContext()->shop() && $nb_shop > 1) { $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON a.`id_category` = cs.`id_category`'; $this->_where = ' AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true); @@ -137,7 +142,13 @@ class AdminCategoriesControllerCore extends AdminController if ($nb_shop == 1 && $count_categories_without_parent > 1) $categories_name = $this->l('Root'); else - $categories_name = stripslashes($this->_category->getName()); + if (empty($categories_name)) + { + $categories_name = new Category($id_parent); + $categories_name = stripslashes($categories_name->getName()); + } + else + $categories_name = stripslashes($this->_category->getName()); $root = Category::getRootCategory(); if (!is_array($root->name) && empty($root->name)) { diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 758e23999..0ed0a679f 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -2511,9 +2511,15 @@ class AdminProductsControllerCore extends AdminController else $selected_cat = Product::getProductCategoriesFull($product->id, $this->default_form_language); } - + $root_category = Category::getRootCategory(); + if (!$root_category->id_category) + { + $root_category->id_category = 0; + $root_category->name = $this->l('Root'); + } + $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name); $translations = array( - 'Home' => $this->l('Home'), + 'Root' => $root_category, 'selected' => $this->l('selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), diff --git a/controllers/admin/AdminScenesController.php b/controllers/admin/AdminScenesController.php index e74abded0..1a5554588 100644 --- a/controllers/admin/AdminScenesController.php +++ b/controllers/admin/AdminScenesController.php @@ -238,8 +238,15 @@ class AdminScenesControllerCore extends AdminController foreach (Scene::getIndexedCategories($obj->id) as $k => $row) $selected_cat[] = $row['id_category']; + $root_category = Category::getRootCategory(); + if (!$root_category->id_category) + { + $root_category->id_category = 0; + $root_category->name = $this->l('Root'); + } + $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name); $trads = array( - 'Home' => $this->l('Home'), + 'Root' => $root_category, 'selected' => $this->l('selected'), 'Check all' => $this->l('Check all'), 'Check All' => $this->l('Check All'), diff --git a/controllers/admin/AdminShopController.php b/controllers/admin/AdminShopController.php index c75c0764f..15b7f859d 100755 --- a/controllers/admin/AdminShopController.php +++ b/controllers/admin/AdminShopController.php @@ -491,10 +491,11 @@ class AdminShopControllerCore extends AdminController public function initCategoriesAssociation($id_root = 1) { $id_shop = Tools::getValue('id_shop'); + $shop = new Shop($id_shop); $selected_cat = Shop::getCategories($id_shop); if ($this->context->shop() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) - $root_category = new Category($id_shop); + $root_category = new Category($shop->id_category); else $root_category = new Category($id_root); $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name[$this->context->language->id]);