[*] BO : categories multishop improved
This commit is contained in:
@@ -28,27 +28,20 @@
|
||||
|
||||
{block name=leadin}
|
||||
<div class="cat_bar2">
|
||||
{if count($categories_tree) == 0}
|
||||
{if $category_root->id_category == 0}
|
||||
<img src="../img/admin/home.gif" alt="" /> {$category_root->name}
|
||||
{assign var=i value=0}
|
||||
{foreach $categories_tree key=key item=category}
|
||||
{if $i++ == 0}
|
||||
<img src="../img/admin/home.gif" alt="" />
|
||||
{assign var=params_url value=""}
|
||||
{else}
|
||||
<img src="../img/admin/home.gif" alt="" /> {$categories_name}
|
||||
{assign var=params_url value="&id_category={$category.id_category}&viewcategory"}
|
||||
{/if}
|
||||
{else}
|
||||
{if $category_root->id_category == 0}
|
||||
<a href="{$currentIndex}&token={$token}"><img src="../img/admin/home.gif" alt="" /> {$category_root->name}</a> >
|
||||
{if $key == 0}
|
||||
{$category.name}
|
||||
{else}
|
||||
<a href="{$currentIndex}&id_category={$category_root->id_category}&token={$token}"><img src="../img/admin/home.gif" alt="" /> {$category_root->name}</a> >
|
||||
<a href="{$currentIndex}{$params_url}&token={$token}">{$category.name}</a> >
|
||||
{/if}
|
||||
|
||||
{foreach $categories_tree key=key item=category}
|
||||
{if $key == 0}
|
||||
{$category.name}
|
||||
{else}
|
||||
<a href="{$currentIndex}&token={$token}&id_category={$category.id_category}&viewcategory">{$category.name}</a> >
|
||||
{/if}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
{if isset($delete_category) && $delete_category}
|
||||
<form action="{$REQUEST_URI}" method="post">
|
||||
|
||||
+34
-24
@@ -390,19 +390,21 @@ class CategoryCore extends ObjectModel
|
||||
*/
|
||||
public static function regenerateEntireNtree()
|
||||
{
|
||||
$categories = Db::getInstance()->executeS('SELECT id_category, id_parent FROM '._DB_PREFIX_.'category ORDER BY id_category ASC');
|
||||
$categories = Db::getInstance()->executeS('SELECT id_category, id_parent FROM '._DB_PREFIX_.'category ORDER BY id_parent, position ASC');
|
||||
$categories_array = array();
|
||||
foreach ($categories as $category)
|
||||
$categories_array[(int)$category['id_parent']]['subcategories'][(int)$category['id_category']] = 1;
|
||||
$n = 1;
|
||||
Category::_subTree($categories_array, 1, $n);
|
||||
$categories_array[$category['id_parent']]['subcategories'][] = $category['id_category'];
|
||||
$n = 1;
|
||||
|
||||
if (isset($categories_array[0]) && $categories_array[0]['subcategories'])
|
||||
Category::_subTree($categories_array, $categories_array[0]['subcategories'][0], $n);
|
||||
}
|
||||
|
||||
protected static function _subTree(&$categories, $id_category, &$n)
|
||||
{
|
||||
$left = (int)$n++;
|
||||
$left = $n++;
|
||||
if (isset($categories[(int)$id_category]['subcategories']))
|
||||
foreach (array_keys($categories[(int)$id_category]['subcategories']) as $id_subcategory)
|
||||
foreach ($categories[(int)$id_category]['subcategories'] as $id_subcategory)
|
||||
Category::_subTree($categories, (int)$id_subcategory, $n);
|
||||
$right = (int)$n++;
|
||||
|
||||
@@ -660,7 +662,7 @@ class CategoryCore extends ObjectModel
|
||||
*/
|
||||
public static function getHomeCategories($id_lang, $active = true)
|
||||
{
|
||||
return Category::getChildren(1, $id_lang, $active);
|
||||
return self::getChildren(1, $id_lang, $active);
|
||||
}
|
||||
|
||||
public static function getRootCategory($id_lang = null, Shop $shop = null)
|
||||
@@ -671,17 +673,13 @@ class CategoryCore extends ObjectModel
|
||||
if (!$shop)
|
||||
$shop = $context->shop;
|
||||
|
||||
// context : no multishop
|
||||
if (count(Shop::getShops()) == 1)
|
||||
if (count(Category::getCategoriesWithoutParent()) > 1)
|
||||
$category = new Category();
|
||||
else
|
||||
$category = new Category($shop->getCategory(), $id_lang);
|
||||
else // context : multishop
|
||||
if (count(Category::getCategoriesWithoutParent()) > 1 && $context->shop() != Shop::CONTEXT_SHOP)
|
||||
$category = new Category();
|
||||
else
|
||||
$category = new Category($shop->getCategory(), $id_lang);
|
||||
$is_more_than_one_root_category = count(Category::getCategoriesWithoutParent()) > 1;
|
||||
if ((!Shop::isFeatureActive() && $is_more_than_one_root_category) ||
|
||||
Shop::isFeatureActive() && $is_more_than_one_root_category && $context->shop() != Shop::CONTEXT_SHOP)
|
||||
$category = Category::getTopCategory();
|
||||
else
|
||||
$category = new Category($shop->getCategory(), $id_lang);
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
@@ -932,17 +930,20 @@ class CategoryCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON (c.`id_category` = cl.`id_category`
|
||||
AND `id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('cl').')';
|
||||
if (count(Shop::getShops()) > 1 && $context->shop() == Shop::CONTEXT_SHOP)
|
||||
if (Shop::isFeatureActive() && $context->shop() == Shop::CONTEXT_SHOP)
|
||||
$sql .= '
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
ON c.`id_category` = cs.`id_category`';
|
||||
$sql .= '
|
||||
WHERE c.`id_category` = '.(int)$id_current;
|
||||
if (count(Shop::getShops()) > 1 && $context->shop() == Shop::CONTEXT_SHOP)
|
||||
if (Shop::isFeatureActive() && $context->shop() == Shop::CONTEXT_SHOP)
|
||||
$sql .= '
|
||||
AND cs.`id_shop` = '.(int)$context->shop->getID(true);
|
||||
$root_category = Category::getRootCategory();
|
||||
if ($context->shop() == Shop::CONTEXT_SHOP && (!Tools::isSubmit('id_category') || (int)Tools::getValue('id_category') == (int)$root_category->id_category || (int)$root_category->id_category == (int)$context->shop->id_category))
|
||||
if (Shop::isFeatureActive() && $context->shop() == Shop::CONTEXT_SHOP &&
|
||||
(!Tools::isSubmit('id_category') ||
|
||||
(int)Tools::getValue('id_category') == (int)$root_category->id_category ||
|
||||
(int)$root_category->id_category == (int)$context->shop->id_category))
|
||||
$sql .= '
|
||||
AND c.`id_parent` != 0';
|
||||
|
||||
@@ -952,7 +953,7 @@ class CategoryCore extends ObjectModel
|
||||
$categories[] = $result[0];
|
||||
else if (!$categories)
|
||||
$categories = array();
|
||||
if (!$result || $result[0]['id_category'] == $context->shop->id_category)
|
||||
if (!$result || ($result[0]['id_category'] == $context->shop->id_category && Shop::isFeatureActive()))
|
||||
return $categories;
|
||||
$id_current = $result[0]['id_parent'];
|
||||
}
|
||||
@@ -1317,7 +1318,7 @@ class CategoryCore extends ObjectModel
|
||||
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
|
||||
WHERE `level_depth` = 1
|
||||
');
|
||||
}
|
||||
|
||||
@@ -1328,5 +1329,14 @@ class CategoryCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'shop`
|
||||
WHERE `id_category` = '.(int)$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTopCategory()
|
||||
{
|
||||
$id_category = Db::getInstance()->getValue('
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category`
|
||||
WHERE `id_parent` = 0
|
||||
');
|
||||
return new Category($id_category);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -973,7 +973,9 @@ class ToolsCore
|
||||
if ($categoryType === 'products')
|
||||
{
|
||||
$interval = Category::getInterval($id_category);
|
||||
$intervalRoot = Category::getInterval($context->shop->getCategory());
|
||||
$id_root_category = $context->shop->getCategory();
|
||||
$root_category = new Category($id_root_category);
|
||||
$intervalRoot = Category::getInterval($id_root_category);
|
||||
if ($interval)
|
||||
{
|
||||
$sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
|
||||
@@ -985,6 +987,7 @@ class ToolsCore
|
||||
AND c.nright <= '.$intervalRoot['nright'].'
|
||||
AND cl.id_lang = '.(int)$context->language->id.'
|
||||
AND c.active = 1
|
||||
AND c.level_depth > '.(int)$root_category->level_depth.'
|
||||
ORDER BY c.level_depth ASC';
|
||||
$categories = Db::getInstance()->executeS($sql);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<field name="active"/>
|
||||
</fields>
|
||||
<entities>
|
||||
<category id="Home" id_parent="" active="1" is_root_category="1"/>
|
||||
<category id="Root" id_parent="" active="1"/>
|
||||
<category id="Home" id_parent="Root" active="1" is_root_category="1"/>
|
||||
</entities>
|
||||
</entity_category>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<entity_category>
|
||||
<category id="Root" id_shop="1">
|
||||
<name>Root</name>
|
||||
<description/>
|
||||
<link_rewrite>root</link_rewrite>
|
||||
<meta_title/>
|
||||
<meta_keywords/>
|
||||
<meta_description/>
|
||||
</category>
|
||||
<category id="Home" id_shop="1">
|
||||
<name>Start</name>
|
||||
<description/>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<entity_category>
|
||||
<category id="Root" id_shop="1">
|
||||
<name>Root</name>
|
||||
<description/>
|
||||
<link_rewrite>root</link_rewrite>
|
||||
<meta_title/>
|
||||
<meta_keywords/>
|
||||
<meta_description/>
|
||||
</category>
|
||||
<category id="Home" id_shop="1">
|
||||
<name>Home</name>
|
||||
<description/>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<entity_category>
|
||||
<category id="Root" id_shop="1">
|
||||
<name>Root</name>
|
||||
<description/>
|
||||
<link_rewrite>root</link_rewrite>
|
||||
<meta_title/>
|
||||
<meta_keywords/>
|
||||
<meta_description/>
|
||||
</category>
|
||||
<category id="Home" id_shop="1">
|
||||
<name>Inicio</name>
|
||||
<description/>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<entity_category>
|
||||
<category id="Root" id_shop="1">
|
||||
<name>Root</name>
|
||||
<description/>
|
||||
<link_rewrite>root</link_rewrite>
|
||||
<meta_title/>
|
||||
<meta_keywords/>
|
||||
<meta_description/>
|
||||
</category>
|
||||
<category id="Home" id_shop="1">
|
||||
<name>Accueil</name>
|
||||
<description/>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<entity_category>
|
||||
<category id="Root" id_shop="1">
|
||||
<name>Root</name>
|
||||
<description/>
|
||||
<link_rewrite>root</link_rewrite>
|
||||
<meta_title/>
|
||||
<meta_keywords/>
|
||||
<meta_description/>
|
||||
</category>
|
||||
<category id="Home" id_shop="1">
|
||||
<name>Home page</name>
|
||||
<description/>
|
||||
|
||||
@@ -219,7 +219,7 @@ class InstallModelInstall extends InstallAbstractModel
|
||||
$shop = new Shop();
|
||||
$shop->active = true;
|
||||
$shop->id_group_shop = $group_shop->id;
|
||||
$shop->id_category = 1;
|
||||
$shop->id_category = 2;
|
||||
$shop->id_theme = 1;
|
||||
$shop->name = 'Default';
|
||||
if (!$shop->add())
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
function generate_root_category_for_multishop()
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'category` SET `level_depth`=`level_depth`+1
|
||||
');
|
||||
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'category` (`id_parent`, `level_depth`, `active`, `date_add`, `date_upd`, `is_root_category`) VALUES
|
||||
(0, 0, 1, NOW(), NOW(), 0)
|
||||
');
|
||||
$id = Db::getInstance()->Insert_ID();
|
||||
|
||||
$langs = Db::getInstance()->executeS('
|
||||
SELECT `id_lang`
|
||||
FROM `'._DB_PREFIX_.'lang`
|
||||
');
|
||||
|
||||
$shops = Db::getInstance()->executeS('
|
||||
SELECT `id_shop`
|
||||
FROM `'._DB_PREFIX_.'shop`
|
||||
');
|
||||
|
||||
$data = array();
|
||||
foreach ($langs as $lang)
|
||||
foreach ($shops as $shop)
|
||||
$data[] = array(
|
||||
'id_lang' => $lang['id_lang'],
|
||||
'id_shop' => $shop['id_shop'],
|
||||
'id_category' => $id,
|
||||
'name' => 'Root',
|
||||
'link_rewrite' => '',
|
||||
);
|
||||
Db::getInstance()->autoExecute(_DB_PREFIX_.'category_lang', $data, 'INSERT');
|
||||
|
||||
Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'category`
|
||||
SET `id_parent` = '.(int)$id.'
|
||||
WHERE `id_parent` = 0 AND `id_category` <> '.(int)$id.'
|
||||
');
|
||||
|
||||
Category::regenerateEntireNtree();
|
||||
}
|
||||
@@ -18,3 +18,14 @@ WHERE `name` = "order fenced" AND (`id_lang` = 1 OR `id_lang` = 3 OR `id_lang` =
|
||||
UPDATE `PREFIX_supply_order_state_lang`
|
||||
SET `name` = "Commande cloturée"
|
||||
WHERE `name` = "order fenced" AND id_lang = 2;
|
||||
|
||||
|
||||
CREATE TABLE `PREFIX_category_shop` (
|
||||
`id_category` int(11) NOT NULL,
|
||||
`id_shop` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id_category`, `id_shop`),
|
||||
UNIQUE KEY `id_category_shop` (`id_category`,`id_shop`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
/* PHP:generate_root_category_for_multishop(); */;
|
||||
Reference in New Issue
Block a user