[*] BO : Adding category management with multishop

This commit is contained in:
vChabot
2012-01-09 15:13:46 +00:00
parent 953dfe5792
commit 2204a2b653
22 changed files with 527 additions and 52 deletions
+2 -2
View File
@@ -725,9 +725,9 @@ if (Tools::isSubmit('getAdminHomeElement'))
die(Tools::jsonEncode($result));
}
if (Tools::isSubmit('getChildrenCategories') && Tools::getValue('id_category_parent'))
if (Tools::isSubmit('getChildrenCategories') && Tools::isSubmit('id_category_parent'))
{
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id);
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id, null, Tools::getValue('use_shop_context'));
die(Tools::jsonEncode($children_categories));
}
@@ -29,9 +29,17 @@
{block name=leadin}
<div class="cat_bar2">
{if count($categories_tree) == 0}
&nbsp;<img src="../img/admin/home.gif" alt="" /> {l s='Home'}
{if $category_root->id_category == 0}
&nbsp;<img src="../img/admin/home.gif" alt="" /> {$category_root->name}
{else}
&nbsp;<img src="../img/admin/home.gif" alt="" /> {$categories_name}
{/if}
{else}
&nbsp;<a href="{$currentIndex}&token={$token}"><img src="../img/admin/home.gif" alt="" /> {l s='Home'}</a>&nbsp;>&nbsp;
{if $category_root->id_category == 0}
&nbsp;<a href="{$currentIndex}&token={$token}"><img src="../img/admin/home.gif" alt="" /> {$category_root->name}</a>&nbsp;>&nbsp;
{else}
&nbsp;<a href="{$currentIndex}&id_category={$category_root->id_category}&token={$token}"><img src="../img/admin/home.gif" alt="" /> {$category_root->name}</a>&nbsp;>&nbsp;
{/if}
{foreach $categories_tree key=key item=category}
{if $key == 0}
@@ -291,6 +291,8 @@
{include file='helper/assoshop.tpl' input=$input fields_value=$fields_value}
{elseif $input.type == 'categories'}
{include file='helper/form/form_category.tpl' categories=$input.values}
{elseif $input.type == 'categories_select'}
{$input.category_tree}
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
{$asso_shop}
{elseif $input.type == 'color'}
@@ -29,7 +29,7 @@
var use_radio = {if $categories.use_radio}1{else}0{/if};
var selectedCat = '{implode value=$categories.selected_cat}';
var selectedLabel = '{$categories.trads.selected}';
var home = '{$categories.trads.Home}';
var home = '{$categories.trads.Root.name}';
var use_radio = {if $categories.use_radio}1{else}0{/if};
$(document).ready(function(){
buildTreeView();
@@ -60,13 +60,13 @@
{foreach $categories.selected_cat AS $cat}
{if is_array($cat)}
{if $cat.id_category != 1}
{if $cat.id_category != $categories.trads.Root.id_category}
<input {if in_array($cat.id_category, $categories.disabled_categories)}disabled="disabled"{/if} type="hidden" name="{$categories.input_name}" value="{$cat.id_category}" >
{else}
{assign var=home_is_selected value=true}
{/if}
{else}
{if $cat != 1}
{if $cat != $categories.trads.Root.id_category}
<input {if in_array($cat, $categories.disabled_categories)}disabled="disabled"{/if} type="hidden" name="{$categories.input_name}" value="{$cat}" >
{else}
{assign var=home_is_selected value=true}
@@ -74,14 +74,14 @@
{/if}
{/foreach}
<ul id="categories-treeview" class="filetree">
<li id="1" class="hasChildren">
<li id="$categories.trads.Root.id_category" class="hasChildren">
<span class="folder">
<input type="{if !$categories.use_radio}checkbox{else}radio{/if}"
name="{$categories.input_name}"
value="1"
value="$categories.trads.Root.id_category"
{if $home_is_selected}checked{/if}
onclick="clickOnCategoryBox($(this));" />
{$categories.trads.Home}
{$categories.trads.Root.name}
</span>
<ul>
<li><span class="placeholder">&nbsp;</span></li>
@@ -39,7 +39,25 @@
{block name="start_field_block"}
<div class="margin-form">
{if $input.type == 'theme'}
{if $input.type == 'select' && $input.name == 'id_category'}
<script type="text/javascript">
$(document).ready(function(){
$("#id_category").change(function(){
$.ajax({
type: "POST",
url : "{$current}",
async: true,
dataType: "html",
data : "ajax=true&id_category="+$(this).val()+"&use_shop_context=false&getCategoriesFromRootCategory=true&token={$token}",
success : function(res)
{
$('#categories-treeview').parent().html(res);
}
});
});
});
</script>
{else if $input.type == 'theme'}
{foreach $input.values as $theme}
<div class="select_theme {if $theme->id == $fields_value.id_theme_checked}select_theme_choice{/if}" onclick="$(this).find('input').attr('checked', true); $('.select_theme').removeClass('select_theme_choice'); $(this).toggleClass('select_theme_choice');">
{$theme->name}<br />
+119 -18
View File
@@ -74,6 +74,9 @@ class CategoryCore extends ObjectModel
/** @var string Object last modification date */
public $date_upd;
/** @var boolean is Category Root */
public $is_root_category;
public $groupBox;
protected static $_links = array();
@@ -92,6 +95,7 @@ class CategoryCore extends ObjectModel
'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
'is_root_category' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'position' => array('type' => self::TYPE_INT),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
@@ -639,12 +643,24 @@ class CategoryCore extends ObjectModel
public static function getRootCategory($id_lang = null, Shop $shop = null)
{
$context = Context::getContext();
if (is_null($id_lang))
$id_lang = Context::getContext()->language->id;
$id_lang = $context->language->id;
if (!$shop)
$shop = Context::getContext()->shop;
$shop = $context->shop;
return new Category($shop->getCategory(), $id_lang);
// 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);
return $category;
}
/**
@@ -663,7 +679,9 @@ class CategoryCore extends ObjectModel
SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.Context::getContext()->shop->addSqlRestrictionOnLang('cl').'
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category`
WHERE `id_lang` = '.(int)$id_lang.'
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true).'
AND c.`id_parent` = '.(int)$id_parent.'
'.($active ? 'AND `active` = 1' : '').'
ORDER BY `position` ASC');
@@ -694,7 +712,7 @@ class CategoryCore extends ObjectModel
* @param int $id_lang
* @return array
*/
public static function getChildrenWithNbSelectedSubCat($id_parent, $selected_cat, $id_lang, Shop $shop = null)
public static function getChildrenWithNbSelectedSubCat($id_parent, $selected_cat, $id_lang, Shop $shop = null, $use_shop_context = true)
{
if (!$shop)
$shop = Context::getContext()->shop;
@@ -712,8 +730,16 @@ class CategoryCore extends ObjectModel
AND c3.`id_category` IN ('.implode(',', array_map('intval', $selected_cat)).')
)' : '0').' AS nbSelectedSubCat
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.$shop->addSqlRestrictionOnLang('cl').'
WHERE `id_lang` = '.(int)$id_lang.'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.$shop->addSqlRestrictionOnLang('cl');
if (Context::getContext()->shop() == Shop::CONTEXT_SHOP && $use_shop_context)
$sql .= '
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category`';
$sql .= '
WHERE `id_lang` = '.(int)$id_lang;
if (Context::getContext()->shop() == Shop::CONTEXT_SHOP && $use_shop_context)
$sql .= '
AND cs.`id_shop` = '.(int)$shop->getID(true);
$sql .= '
AND c.`id_parent` = '.(int)$id_parent.'
ORDER BY `position` ASC';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
@@ -870,25 +896,41 @@ class CategoryCore extends ObjectModel
*/
public function getParentsCategories($id_lang = null)
{
$context = Context::getContext();
if (is_null($id_lang))
$id_lang = Context::getContext()->language->id;
$id_lang = $context->language->id;
$categories = null;
$id_current = $this->id;
while (true)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
ON (c.`id_category` = cl.`id_category`
AND `id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('cl').')
WHERE c.`id_category` = '.(int)$id_current.'
AND c.`id_parent` != 0
');
$sql = '
SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'category` c
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)
$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)
$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))
$sql .= '
AND c.`id_parent` != 0';
isset($result[0]) ? $categories[] = $result[0] : $categories = array();
if (!$result || $result[0]['id_parent'] == 1)
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if (isset($result[0]))
$categories[] = $result[0];
else if (!$categories)
$categories = array();
if (!$result || $result[0]['id_category'] == $context->shop->id_category)
return $categories;
$id_current = $result[0]['id_parent'];
}
@@ -1197,5 +1239,64 @@ class CategoryCore extends ObjectModel
return $categories;
}
/**
* @param $id_shop
* @return bool
*/
public function isParentCategoryAvailable($id_shop)
{
return (bool)Db::getInstance()->getValue('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
ON c.`id_category` = cs.`id_category`
WHERE cs.`id_shop` = '.(int)$id_shop.'
AND c.`id_parent` = '.(int)$this->id_parent);
}
/**
* Add association between shop and cateogries
* @param int $id_shop
* @return bool
*/
public function addShop($id_shop)
{
$sql = '';
if (!$id_shop)
{
foreach (Shop::getShops(true) as $shop)
$sql .= '('.(int)$this->id.', '.(int)$shop['id_shop'].'),';
// removing last comma to avoid SQL error
$sql = substr($sql, 0, strlen($sql) - 1);
} else
$sql .= '('.(int)$this->id.', '.(int)$id_shop.')';
return Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES
'.$sql);
}
public function getRootCategories($id_lang = null, $active = true)
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT(c.`id_category`), cl.`name`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = c.`id_category` AND cl.`id_lang`='.(int)$id_lang.')
WHERE `is_root_category` = 1
'.(($active) ? 'AND `active` = 1': ''));
}
public function getCategoriesWithoutParent()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT 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
');
}
}
+4
View File
@@ -598,8 +598,10 @@ class SearchCore
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
WHERE p.`active` = 1
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().'
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM '._DB_PREFIX_.'customer_group
WHERE id_customer = '.(int)$id_customer.')').'
@@ -633,8 +635,10 @@ class SearchCore
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`)
'.Product::sqlStock('p', 0).'
WHERE p.`active` = 1
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().'
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM '._DB_PREFIX_.'customer_group
WHERE id_customer = '.(int)$id_customer.')').'
+5 -6
View File
@@ -142,7 +142,6 @@ class HelperCore
$html = '
<script type="text/javascript">
var inputName = "'.$input_name.'";
var use_radio = '.($use_radio ? '1' : '0').';
';
if (sizeof($selected_cat) > 0)
{
@@ -155,7 +154,7 @@ class HelperCore
$html .= 'var selectedCat = "";';
$html .= '
var selectedLabel = \''.$trads['selected'].'\';
var home = \''.$trads['Home'].'\';
var home = \''.$trads['Root']['name'].'\';
var use_radio = '.(int)$use_radio.';';
if (!$use_in_popup)
$html .= '
@@ -187,7 +186,7 @@ class HelperCore
if (is_array($cat))
{
$disabled = in_array($cat['id_category'], $disabled_categories);
if ($cat['id_category'] != 1)
if ($cat['id_category'] != $trads['Root']['id_category'])
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat['id_category'].'" >';
else
$home_is_selected = true;
@@ -195,7 +194,7 @@ class HelperCore
else
{
$disabled = in_array($cat, $disabled_categories);
if ($cat != 1)
if ($cat != $trads['Root']['id_category'])
$html .= '<input '.($disabled?'disabled="disabled"':'').' type="hidden" name="'.$input_name.'" value="'.$cat.'" >';
else
$home_is_selected = true;
@@ -203,8 +202,8 @@ class HelperCore
}
$html .= '
<ul id="categories-treeview" class="filetree">
<li id="1" class="hasChildren">
<span class="folder"> <input type="'.(!$use_radio ? 'checkbox' : 'radio').'" name="'.$input_name.'" value="1" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Home'].'</span>
<li id="'.$trads['Root']['id_category'].'" class="hasChildren">
<span class="folder"> <input type="'.(!$use_radio ? 'checkbox' : 'radio').'" name="'.$input_name.'" value="1" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Root']['name'].'</span>
<ul>
<li><span class="placeholder">&nbsp;</span></li>
</ul>
+127
View File
@@ -71,6 +71,7 @@ class ShopCore extends ObjectModel
private static $asso_tables = array(
'carrier' => array('type' => 'shop'),
'carrier_lang' => array('type' => 'fk_shop'),
'category' => array('type' => 'shop'),
'category_lang' => array('type' => 'fk_shop'),
'cms' => array('type' => 'shop'),
'contact' => array('type' => 'shop'),
@@ -909,4 +910,130 @@ class ShopCore extends ObjectModel
{
return Context::getContext()->shop->getID(true);
}
/**
* @static
* @param int $id
* @return array
*/
public static function getCategories($id = 0, $only_id = true)
{
// build query
$query = new DbQuery();
if ($only_id)
$query->select('cs.`id_category`');
else
$query->select('DISTINCT cs.`id_category`, cl.`name`, cl.`link_rewrite`');
$query->from('category_shop', 'cs')
->leftJoin('category_lang', 'cl', 'cl.`id_category` = cs.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id)
->where('cs.`id_shop` = '.(int)$id);//d($query->__toString());
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
if ($only_id)
{
$array = array();
foreach ($result as $row)
$array[] = $row['id_category'];
$array = array_unique($array);
}
else
return $result;
return $array;
}
/**
* Update categories for a shop
*
* @param string $productCategories Categories list to associate a shop
* @return array Update/insertion result
*/
public function updateCategories($categories)
{
// if array is empty or if the default category is not selected, return false
if (empty($categories) || !in_array($this->id_category, $categories))
return false;
// delete categories for this shop
$this->deleteCategories();
// and add $categories to this shop
return $this->addToCategories($categories);
}
/**
* Delete shop from category $id_category
* @param int $id_category
* @return bool
*/
public function deleteCategory($id_category)
{
return Db::getInstance()->execute(
'DELETE FROM `'._DB_PREFIX_.'category_shop`
WHERE `id_shop` = '.(int)$this->id.'
AND id_category = '.(int)$id_category.''
);
}
/**
* Delete every categories
* @return bool
*/
public function deleteCategories()
{
return Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE `id_shop` = '.(int)$this->id.'
');
}
/**
* Add some categories to a shop
* @param array $categories
* @return bool
*/
public function addToCategories($categories)
{
if (!is_array($categories))
return false;
$sql = '
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES';
foreach ($categories as $c)
$sql .= '("'.(int)$c.'", "'.(int)$this->id.'"),';
// removing last comma to avoid SQL error
$sql = substr($sql, 0, strlen($sql) - 1);
return Db::getInstance()->execute($sql);
}
/**
* @static
* @param $id_category
* @return bool
*/
public static function isCategoryAvailable($id_category)
{
return (bool)Db::getInstance()->getValue('
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_shop`
WHERE `id_category` = '.(int)$id_category.'
AND `id_shop` = '.(int)Context::getContext()->shop->getID(true));
}
/**
* @static
* @param $id_product
* @return bool
*/
public static function isProductAvailable($id_product)
{
return (bool)Db::getInstance()->getValue('
SELECT p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'category_product` cp
ON p.`id_product` = cp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
ON cp.`id_category` = cs.`id_category`
WHERE p.`id_product` = '.(int)$id_product.'
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true));
}
}
@@ -82,12 +82,18 @@ class AdminCategoriesControllerCore extends AdminController
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
parent::__construct();
}
public function init()
{
parent::init();
// context->shop is set in the init() function, so we move the _category instanciation after that
if ($id_category = Tools::getvalue('id_category'))
$this->_category = new Category($id_category);
else
$this->_category = new Category(1);
parent::__construct();
$this->_category = new Category($this->context->shop->id_category);
}
public function setMedia()
@@ -104,14 +110,43 @@ class AdminCategoriesControllerCore extends AdminController
$this->addRowAction('add');
$this->addRowAction('view');
$this->_filter .= ' AND `id_parent` = '.(int)$this->_category->id.' ';
$count_categories_without_parent = count(Category::getCategoriesWithoutParent());
$nb_shop = count(Shop::getShops());
if (Tools::isSubmit('id_category'))
$id_parent = $this->_category->id;
else if ($nb_shop == 1 && $count_categories_without_parent > 1)
$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())
{
$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);
}
$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))
$categories_tree = array(array('name' => $this->_category->name[$this->context->language->id]));
asort($categories_tree);
$categories_name = stripslashes($this->_category->getName());
if ($nb_shop == 1 && $count_categories_without_parent > 1)
$categories_name = $this->l('Root');
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;
return parent::renderList();
}
@@ -140,10 +175,16 @@ class AdminCategoriesControllerCore extends AdminController
public function initToolbar()
{
if (empty($this->display))
{
$this->toolbar_btn['new-url'] = array(
'href' => self::$currentIndex.'&amp;add'.$this->table.'root&amp;token='.$this->token,
'desc' => $this->l('Add new root category')
);
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&amp;add'.$this->table.'&amp;token='.$this->token,
'desc' => $this->l('Add new')
);
}
if (Tools::getValue('id_category') && !Tools::isSubmit('updatecategory'))
{
$this->toolbar_btn['edit'] = array(
@@ -166,11 +207,22 @@ class AdminCategoriesControllerCore extends AdminController
parent::initToolbar();
}
public function initProcess()
{
if (Tools::isSubmit('add'.$this->table.'root') && $this->tabAccess['add'])
{
$this->action = 'add'.$this->table.'root';
$this->display = 'edit';
}
return parent::initProcess();
}
public function renderForm()
{
$this->initToolbar();
$obj = $this->loadObject(true);
$selected_cat = array(isset($obj->id_parent) ? $obj->id_parent : Tools::getValue('id_parent', 1));
$id_shop = Context::getContext()->shop->getID(true);
$selected_cat = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? $obj->id_parent : Tools::getValue('id_parent', 1));
$unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
$guest = new Group(Configuration::get('PS_GUEST_GROUP'));
$default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
@@ -178,7 +230,13 @@ class AdminCategoriesControllerCore extends AdminController
$unidentified_group_information = sprintf($this->l('%s - All persons without a customer account or unauthenticated.'), "<b>".$unidentified->name[$this->context->language->id]."</b>");
$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>");
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'));
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
@@ -222,7 +280,7 @@ class AdminCategoriesControllerCore extends AdminController
'name' => 'id_parent',
'values' => array(
'trads' => array(
'Home' => $this->l('Home'),
'Root' => $root_category,
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All')
@@ -234,6 +292,26 @@ class AdminCategoriesControllerCore extends AdminController
'disabled_categories' => array(4),
)
),
array(
'type' => 'radio',
'label' => $this->l('Root Category:'),
'name' => 'is_root_category',
'required' => false,
'is_bool' => true,
'class' => 't',
'values' => array(
array(
'id' => 'is_root_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'is_root_off',
'value' => 0,
'label' => $this->l('No')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Description:'),
@@ -296,6 +374,8 @@ class AdminCategoriesControllerCore extends AdminController
'class' => 'button'
)
);
if (Tools::isSubmit('add'.$this->table.'root'))
unset($this->fields_form['input'][2],$this->fields_form['input'][3]);
if (!($obj = $this->loadObject(true)))
return;
@@ -335,6 +415,12 @@ class AdminCategoriesControllerCore extends AdminController
{
$id_category = (int)Tools::getValue('id_category');
$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;
}
if ($id_category)
{
if ($id_category != $id_parent)
+8 -2
View File
@@ -247,11 +247,17 @@ 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'));
$this->fields_value['reduction'] = isset($group->reduction) ? $group->reduction : 0;
$trads = array(
'Home' => $this->l('Home'),
'Root' => $root_category,
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),
+11 -1
View File
@@ -2144,6 +2144,9 @@ class AdminProductsControllerCore extends AdminController
$this->_errors[] = 'Unable to load object';
else
{
if ($this->object->id && !Shop::isProductAvailable($this->object->id))
$this->_displayUnavailableProductWarning();
$this->_displayDraftWarning($this->object->active);
$this->initPack($this->object);
@@ -2515,8 +2518,15 @@ class AdminProductsControllerCore extends AdminController
$selected_cat = Product::getProductCategoriesFull($product->id, $this->default_form_language);
}
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'));
$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'),
+56 -3
View File
@@ -144,7 +144,7 @@ class AdminShopControllerCore extends AdminController
public function initContent()
{
$shops = Shop::getShopWithoutUrls();
if (count($shops))
if (count($shops) && !$this->ajax)
{
$shop_url_configuration = '';
foreach ($shops as $shop)
@@ -170,8 +170,28 @@ class AdminShopControllerCore extends AdminController
return parent::renderList();
}
public function ajaxProcess()
{
if (Tools::isSubmit('getCategoriesFromRootCategory') && Tools::isSubmit('id_category'))
{
$root_category = new Category((int)Tools::getValue('id_category'));
$root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name[$this->context->language->id]);
$trads = array(
'Root' => $root_category,
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'),
'Expand All' => $this->l('Expand All')
);
echo Helper::renderAdminCategorieTree($trads, array($root_category['id_category']));
}
}
public function postProcess()
{
if (Tools::isSubmit('id_category_default'))
$_POST['id_category'] = Tools::getValue('id_category_default');
if ((Tools::isSubmit('status') ||
Tools::isSubmit('status'.$this->table) ||
(Tools::isSubmit('submitAdd'.$this->table) && Tools::getValue($this->identifier) && !Tools::getValue('active'))) &&
@@ -193,7 +213,7 @@ class AdminShopControllerCore extends AdminController
if (!Validate::isLoadedObject($object = $this->loadObject()))
$this->_errors[] = Tools::displayError('Unable to load this shop.');
else if(!Shop::has_dependency($object->id))
return parent::processDelete($token);
return $object->deleteCategories() && parent::processDelete($token);
else
$this->_errors[] = Tools::displayError('You can\'t delete this shop (customer and/or order dependency)');
@@ -279,7 +299,7 @@ class AdminShopControllerCore extends AdminController
)
);
}
$categories = Category::getCategories($this->context->language->id, false, false);
$categories = Category::getRootCategories($this->context->language->id);
$this->fields_form['input'][] = array(
'type' => 'select',
'label' => $this->l('Category root:'),
@@ -290,6 +310,13 @@ class AdminShopControllerCore extends AdminController
'name' => 'name'
)
);
$this->fields_form['input'][] = array(
'type' => 'categories_select',
'name' => 'categoryBox',
'label' => $this->l('Associated categories :'),
'category_tree' => $this->initCategoriesAssociation($categories[0]['id_category'])
);
$this->fields_form['input'][] = array(
'type' => 'radio',
'label' => $this->l('Status:'),
@@ -419,6 +446,8 @@ class AdminShopControllerCore extends AdminController
*/
public function processAdd($token)
{
if (Tools::isSubmit('id_category_default'))
$_POST['id_category'] = (int)Tools::getValue('id_category_default');
/* Checking fields validity */
$this->validateRules();
@@ -455,6 +484,30 @@ class AdminShopControllerCore extends AdminController
return;
$shop = new Shop($object->id);
$shop->updateCategories(Tools::getValue('categoryBox'));
return $object;
}
public function initCategoriesAssociation($id_root = 1)
{
$id_shop = Tools::getValue('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);
else
$root_category = new Category($id_root);
$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'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),
'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'),
'search' => $this->l('Search a category')
);
return Helper::renderAdminCategorieTree($translations, $selected_cat, 'categoryBox', false, true);
}
}
+5
View File
@@ -49,6 +49,11 @@ class CategoryControllerCore extends FrontController
public function canonicalRedirection($canonicalURL = '')
{
if (!Shop::isCategoryAvailable(Tools::getValue('id_category')))
{
$this->redirect_after = '404';
$this->redirect();
}
if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category))
parent::canonicalRedirection($this->context->link->getCategoryLink($this->category));
}
+8
View File
@@ -302,6 +302,7 @@ CREATE TABLE `PREFIX_category` (
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
`position` int(10) unsigned NOT NULL default '0',
`is_root_category` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id_category`),
KEY `category_parent` (`id_parent`),
KEY `nleftright` (`nleft`,`nright`)
@@ -2367,3 +2368,10 @@ CREATE TABLE IF NOT EXISTS `PREFIX_risk_lang` (
PRIMARY KEY (`id_risk`,`id_lang`),
KEY `id_risk` (`id_risk`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
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;
+5
View File
@@ -1746,3 +1746,8 @@ CREATE TABLE IF NOT EXISTS `PREFIX_linksmenutop_lang` (
`label` VARCHAR( 128 ) NOT NULL ,
INDEX ( `id_link` , `id_lang`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_category_shop` (`id_category`, `id_shop`) VALUES
(2, 1),
(3, 1),
(4, 1);
+3
View File
@@ -1647,3 +1647,6 @@ INSERT INTO `PREFIX_risk_lang` (`id_risk`, `id_lang`, `name`) VALUES
(2, 5, 'Low'),
(3, 5, 'Middle'),
(4, 5, 'Hight');
INSERT INTO `PREFIX_category_shop` (`id_category`, `id_shop`) VALUES
(1, 1);
+4
View File
@@ -2,3 +2,7 @@ SET NAMES 'utf8';
ALTER TABLE `PREFIX_order_state` ADD COLUMN `deleted` tinyint(1) UNSIGNED NOT NULL default '0' AFTER `paid`;
ALTER TABLE `PREFIX_category` ADD COLUMN `is_root_category` tinyint(1) NOT NULL default '0' AFTER `position`;
UPDATE `PREFIX_category` SET `is_root_category` = 1 WHERE `id_category` = 1;
+8
View File
@@ -302,6 +302,7 @@ CREATE TABLE `PREFIX_category` (
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
`position` int(10) unsigned NOT NULL default '0',
`is_root_category` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id_category`),
KEY `category_parent` (`id_parent`),
KEY `nleftright` (`nleft`,`nright`)
@@ -2367,3 +2368,10 @@ CREATE TABLE IF NOT EXISTS `PREFIX_risk_lang` (
PRIMARY KEY (`id_risk`,`id_lang`),
KEY `id_risk` (`id_risk`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
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;
+1 -1
View File
@@ -5,6 +5,6 @@
<field name="active"/>
</fields>
<entities>
<category id="Home" id_parent="" active="1"/>
<category id="Home" id_parent="" active="1" is_root_category="1"/>
</entities>
</entity_category>
+15 -1
View File
@@ -1613,8 +1613,22 @@ class BlockLayered extends Module
$selectedCat = array();
// Translations are not automatic for the moment ;)
if (version_compare(_PS_VERSION_,'1.5','>'))
{
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'));
}
else
{
$root_category = array('id_category' => '1', 'name' => $this->l('Home'));
}
$trads = array(
'Home' => $this->l('Home'),
'Root' => $root_category,
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),
+15 -1
View File
@@ -325,8 +325,22 @@ class Loyalty extends Module
$index = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
$indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index;
// Translations are not automatic for the moment ;)
if (version_compare(_PS_VERSION_,'1.5','>'))
{
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'));
}
else
{
$root_category = array('id_category' => '1', 'name' => $this->l('Home'));
}
$trads = array(
'Home' => $this->l('Home'),
'Root' => $root_category,
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),