[*] BO : categories multishop improved

This commit is contained in:
vChabot
2012-01-19 14:03:33 +00:00
parent 9d41358764
commit 585b670df3
15 changed files with 163 additions and 92 deletions
+14 -35
View File
@@ -93,7 +93,10 @@ class AdminCategoriesControllerCore extends AdminController
if (($id_category = Tools::getvalue('id_category')) && $this->action != 'select_delete')
$this->_category = new Category($id_category);
else
$this->_category = new Category($this->context->shop->id_category);
if (Shop::isFeatureActive() && $this->context->shop() == Shop::CONTEXT_SHOP)
$this->_category = new Category($this->context->shop->id_category);
else
$this->_category = Category::getTopCategory();
}
public function initContent()
@@ -123,22 +126,22 @@ class AdminCategoriesControllerCore extends AdminController
$this->addRowAction('view');
$count_categories_without_parent = count(Category::getCategoriesWithoutParent());
$nb_shop = count(Shop::getShops());
$is_multishop = Shop::isFeatureActive();
if (Tools::isSubmit('id_category'))
$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)
else if (!$is_multishop && $count_categories_without_parent > 1)
$id_parent = 1;
else if ($is_multishop && $count_categories_without_parent == 1)
$id_parent = 2;
else if ($is_multishop && $count_categories_without_parent > 1 && $this->context->shop() != Shop::CONTEXT_SHOP)
$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_SHOP == Context::getContext()->shop() && $nb_shop > 1)
if (Shop::CONTEXT_SHOP == Context::getContext()->shop() && $is_multishop)
{
$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);
@@ -147,29 +150,11 @@ class AdminCategoriesControllerCore extends AdminController
$categories_tree = $this->_category->getParentsCategories();
if (empty($categories_tree)
&& ($this->_category->id_category != 1 || Tools::isSubmit('id_category'))
&& (Shop::CONTEXT_SHOP == Context::getContext()->shop() && $nb_shop == 1 && $count_categories_without_parent > 1))
&& (Shop::CONTEXT_SHOP == Context::getContext()->shop() && !$is_multishop && $count_categories_without_parent > 1))
$categories_tree = array(array('name' => $this->_category->name[$this->context->language->id]));
asort($categories_tree);
if ($nb_shop == 1 && $count_categories_without_parent > 1)
$categories_name = $this->l('Root');
else
if ($this->_category->getName() == '')
{
$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))
{
$root->name = $this->l('Root');
$root->id = $root->id_category = 0;
}
$this->tpl_list_vars['categories_tree'] = $categories_tree;
$this->tpl_list_vars['categories_name'] = $categories_name;
$this->tpl_list_vars['category_root'] = $root;
if (Tools::isSubmit('submitBulkdelete'.$this->table) OR Tools::isSubmit('delete'.$this->table))
$this->tpl_list_vars['delete_category'] = true;
@@ -271,10 +256,7 @@ class AdminCategoriesControllerCore extends AdminController
$guest_group_information = sprintf($this->l('%s - Customer who placed an order with the Guest Checkout.'), "<b>".$guest->name[$this->context->language->id]."</b>");
$default_group_information = sprintf($this->l('%s - All persons who created an account on this site.'), "<b>".$default->name[$this->context->language->id]."</b>");
$root_category = Category::getRootCategory();
if (!$root_category->id_category)
$root_category = array('id_category' => '0', 'name' => $this->l('Root'));
else
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name[$this->context->language->id]);
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
@@ -451,10 +433,7 @@ class AdminCategoriesControllerCore extends AdminController
$id_parent = (int)Tools::getValue('id_parent');
// if true, we are in a root category creation
if (!$id_parent && !Tools::isSubmit('is_root_category'))
{
$_POST['id_parent'] = $id_parent = 0;
$_POST['is_root_category'] = 1;
}
$_POST['is_root_category'] = $_POST['level_depth'] = $_POST['id_parent'] = $id_parent = 1;
if ($id_category)
{
if ($id_category != $id_parent)
+2 -7
View File
@@ -247,13 +247,8 @@ class AdminGroupsControllerCore extends AdminController
)
)
);
if ($this->context->shop() == Shop::CONTEXT_SHOP)
{
$root_category = Category::getRootCategory();
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
}
else
$root_category = array('id_category' => '0', 'name' => $this->l('Root'));
$root_category = Category::getRootCategory();
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name[$this->context->language->id]);
$this->fields_value['reduction'] = isset($group->reduction) ? $group->reduction : 0;
$trads = array(
@@ -2472,12 +2472,7 @@ class AdminProductsControllerCore extends AdminController
$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);
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name[$this->context->language->id]);
$translations = array(
'Root' => $root_category,
'selected' => $this->l('selected'),