From a458d2bdb9c4433268dfce25b7a4e72795b7ca2a Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Thu, 2 Aug 2012 14:53:47 +0000 Subject: [PATCH] //fixed create root category --- classes/Category.php | 2 +- .../admin/AdminCategoriesController.php | 29 +++++++++++-------- controllers/admin/AdminShopController.php | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/classes/Category.php b/classes/Category.php index c4e385fb0..51c0ab67b 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -935,7 +935,7 @@ class CategoryCore extends ObjectModel $categories = null; $id_current = $this->id; - if (count(Category::getCategoriesWithoutParent()) > 1) + if (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) $context->shop->id_category = Category::getTopCategory()->id; elseif (!$context->shop->id) $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT')); diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index d679c0107..e3873add5 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -103,11 +103,10 @@ class AdminCategoriesControllerCore extends AdminController else if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) $this->_category = new Category($this->context->shop->id_category); - else if (count(Category::getCategoriesWithoutParent()) > 1) + else if (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) $this->_category = Category::getTopCategory(); else $this->_category = new Category(Configuration::get('PS_HOME_CATEGORY')); - // if we are not in a shop context, we remove the position column if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) unset($this->fields_list['position']); @@ -146,8 +145,9 @@ class AdminCategoriesControllerCore extends AdminController $this->addRowAction('view'); $count_categories_without_parent = count(Category::getCategoriesWithoutParent()); - $is_multishop = Shop::isFeatureActive(); + $is_multishop = Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE'); $top_category = Category::getTopCategory(); + if (Tools::isSubmit('id_category')) $id_parent = $this->_category->id; else if (!$is_multishop && $count_categories_without_parent > 1) @@ -155,7 +155,10 @@ class AdminCategoriesControllerCore extends AdminController else if ($is_multishop && $count_categories_without_parent == 1) $id_parent = Configuration::get('PS_HOME_CATEGORY'); else if ($is_multishop && $count_categories_without_parent > 1 && Shop::getContext() != Shop::CONTEXT_SHOP) - $id_parent = $top_category->id; + if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) == 1) + $id_parent = $this->context->shop->id_category; + else + $id_parent = $top_category->id; else $id_parent = $this->context->shop->id_category; @@ -509,6 +512,9 @@ class AdminCategoriesControllerCore extends AdminController $this->errors[] = Tools::displayError($this->l('Category cannot be parent of itself.')); } parent::processAdd(); + //if we create a you root category you have to associate to a shop before to add sub categories in. So we redirect to AdminCategories listing + if (Tools::isSubmit('is_root_category')) + Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminCategories').'&conf=3'); } protected function setDeleteMode() @@ -567,16 +573,15 @@ class AdminCategoriesControllerCore extends AdminController public function processFatherlessProducts($id_parent) { - $all_product_asso = array(); - $tmp = Db::getInstance()->executeS('SELECT DISTINCT(`id_product`) FROM `'._DB_PREFIX_.'category_product`'); - foreach ($tmp as $val) - $all_product_asso[] = $val['id_product']; - /* Delete or link products which were not in others categories */ - $fatherless_products = new Collection('Product', Context::getContext()->language->id); - $fatherless_products->where('id_product', 'notin', $all_product_asso); - foreach ($fatherless_products as $poor_product) + $fatherless_products = Db::getInstance()->executeS(' + SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p + '.Shop::addSqlAssociation('product', 'p').' + WHERE p.`id_product` NOT IN (SELECT DISTINCT(cp.`id_product`) FROM `'._DB_PREFIX_.'category_product` cp)'); + + foreach ($fatherless_products as $id_poor_product) { + $poor_product = new Product((int)$id_poor_product); if (Validate::isLoadedObject($poor_product)) { if ($this->remove_products || $id_parent == 0) diff --git a/controllers/admin/AdminShopController.php b/controllers/admin/AdminShopController.php index 6d64cb8b9..c76502dcd 100755 --- a/controllers/admin/AdminShopController.php +++ b/controllers/admin/AdminShopController.php @@ -517,7 +517,7 @@ class AdminShopControllerCore extends AdminController 'id_shop_group' => (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : (isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()), 'id_category' => (Tools::getValue('id_category') ? Tools::getValue('id_category') : - (isset($obj->id_shop_group)) ? $obj->id_shop_group : Shop::getContextShopGroupID()), + (isset($obj->id_category)) ? $obj->id_category : (int)Configuration::get('PS_HOME_CATEGORY')), 'id_theme_checked' => (isset($obj->id_theme) ? $obj->id_theme : $id_theme) );