По прямым ссылкам "запрещенные" категории (и товары этих категорий) будут показываться.
Если родительская категория разрешена, но запрещены дочерние категории, то товары из них не будут показаны в родительской.
Если родительская категория запрещена, но разрешены дочерние категории, то по прямой ссылке товары из дочерних будут показаны в родительской.
Если родительская категория запрещена и зарещены дочерние категории, то по прямой ссылке товары из дочерних не будут показаны в родительской.
Спонсор дополнения - Jeck2000
1. в файле core/tpl/admin/index.tpl.html
после строки
<script type="text/javascript" src="data/admin/admin.js"></script>
вставляем
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
2. в файле menu.tpl.html
2.1 вместо строки
<td class="l2"><a href="{$smarty.const.ADMIN_FILE}?dpt=catalog&sub=products_categories&categoryID=1">{$smarty.const.ADMIN_CATEGORY_ROOT}</a></td>
вставляем
<script type="text/javascript">
{literal}
function InvertAll() {
if (document.getElementById('invertAll').checked)
$("input[id^='cat_enable_']").attr({checked:true});
else
$("input[id^='cat_enable_']").attr({checked:false});
}
{/literal}
</script>
<td class="l2"><input type="checkbox" id="invertAll" onclick="InvertAll();"><a href="{$smarty.const.ADMIN_FILE}?dpt=catalog&sub=products_categories&categoryID=1">{$smarty.const.ADMIN_CATEGORY_ROOT}</a></td>
2.2 секцию
{section name=i loop=$categories}
<table class="adn"><tr><td class="l1">{section name=j loop=$categories[i].level max=$categories[i].level}{if $smarty.section.j.index==$categories[i].level-1}<img src="data/admin/pm.gif" alt="">{else}<img src="data/admin/pmp.gif" alt="">{/if}{/section}{if !$categories[i].ExpandedCategory}{if $categories[i].ExistSubCategories}<a href='{$urlToCategoryTreeExpand}&expandCat={$categories[i].categoryID}'><img src="data/admin/mplus.gif" alt=""></a>{else}<img src="data/admin/dr.gif" alt="">{/if}{else}{if $categories[i].ExistSubCategories}<a href='{$urlToCategoryTreeExpand}&shrinkCat={$categories[i].categoryID}'><img src="data/admin/minus.gif" alt=""></a>{else}<img src="data/admin/dr.gif" alt="">{/if}{/if}</td>
<td class="l2"><a href="{$smarty.const.ADMIN_FILE}?dpt=catalog&sub=products_categories&categoryID={$categories[i].categoryID}&expandCat={$categories[i].categoryID}">{$categories[i].name}</a></td>
<td class="l3"><a href="{$smarty.const.ADMIN_FILE}?categoryID={$categories[i].categoryID}&eaction=cat">{if !$categories[i].ExpandedCategory}{$categories[i].products_count_admin}{else}{$categories[i].products_count_category}{/if}</a></td>
</tr></table>
{/section}
заменяем на
<form method="post" action="/{$smarty.const.ADMIN_FILE}?eaction=cat_enable" name="cat_enable">
{section name=i loop=$categories}
<table class="adn"><tr><td class="l1">{section name=j loop=$categories[i].level max=$categories[i].level}{if $smarty.section.j.index==$categories[i].level-1}<img src="data/admin/pm.gif" alt="">{else}<img src="data/admin/pmp.gif" alt="">{/if}{/section}{if !$categories[i].ExpandedCategory}{if $categories[i].ExistSubCategories}<a href='{$urlToCategoryTreeExpand}&expandCat={$categories[i].categoryID}'><img src="data/admin/mplus.gif" alt=""></a>{else}<img src="data/admin/dr.gif" alt="">{/if}{else}{if $categories[i].ExistSubCategories}<a href='{$urlToCategoryTreeExpand}&shrinkCat={$categories[i].categoryID}'><img src="data/admin/minus.gif" alt=""></a>{else}<img src="data/admin/dr.gif" alt="">{/if}{/if}</td>
<td class="l2">
<input type="checkbox" name="cat_enable_{$categories[i].categoryID}" id="cat_enable_{$categories[i].categoryID}"{if $categories[i].adm_enable} checked{/if}>
<input type="hidden" name="cat_exists_{$categories[i].categoryID}" id="cat_exists_{$categories[i].categoryID}" value=1>
<a href="{$smarty.const.ADMIN_FILE}?dpt=catalog&sub=products_categories&categoryID={$categories[i].categoryID}&expandCat={$categories[i].categoryID}">{$categories[i].name}</a></td>
<td class="l3"><a href="{$smarty.const.ADMIN_FILE}?categoryID={$categories[i].categoryID}&eaction=cat">{if !$categories[i].ExpandedCategory}{$categories[i].products_count_admin}{else}{$categories[i].products_count_category}{/if}</a></td>
</tr></table>
{/section}
<table class="adn"><tr><td align="center"><input type="submit" style="background-color:green;color:white;font-weight:bold;cursor: pointer;" value="Save"></td></tr></table>
</form>
3. в файле category_functions.php
3.1 в функции catGetCategoryCompactCList
вместо строки
" where parent=1".
вставляем
" where parent=1 AND enable=1".
3.2 в функции _recursiveGetCategoryCList
после строки
$row = $fc[(int)$rcat[$i]];
вставляем
if (!isset($row["enable"]) || $row["enable"] == 1)
{
перед строкой
return $result;
вставляем закрывающую фигурную скобку }
}
3.3 в функции catGetSubCategories
вместо строки
$q = db_query("select categoryID from ".CATEGORIES_TABLE." where parent=".(int)$categoryID);
вставляем
$q = db_query("select categoryID from ".CATEGORIES_TABLE." where parent=".(int)$categoryID." AND enable=1");
4. в файле admin.php
4.1 перед строкой
case 'cat':
вставляем
case 'cat_enable':
foreach ($_POST as $key => $value)
{
if (strstr($key, "cat_enable_")) $new_enable[] = str_replace("cat_enable_", "", $key);
if (strstr($key, "cat_exists_")) $cat_exists[] = str_replace("cat_exists_", "", $key);
}
$data = db_query("SELECT categoryID,enable FROM ".CATEGORIES_TABLE);
while ($row = db_fetch_assoc($data))
if (in_array($row['categoryID'],$cat_exists))
{
if (!$row['enable'] && in_array($row['categoryID'],$new_enable))
db_query("UPDATE ".CATEGORIES_TABLE." SET enable=1 WHERE categoryID=".$row['categoryID']);
elseif ($row['enable'] && !in_array($row['categoryID'],$new_enable))
db_query("UPDATE ".CATEGORIES_TABLE." SET enable=0 WHERE categoryID=".$row['categoryID']);
}
Redirect($_SERVER['HTTP_REFERER']);
break;
4.2 вместо последнего (их там три!) вхождения строки
$q = db_query("select categoryID, name, products_count, products_count_admin, parent, picture, subcount FROM ".CATEGORIES_TABLE." ORDER BY sort_order, name");
вставляем
$field = array ('Field' => 'enable', 'Type' => 'tinyint(1)', 'Default' => '1');
$data = mysql_query("desc ".CATEGORIES_TABLE);
while ($row[] = mysql_fetch_assoc($data));
$flag = true;
foreach ($row as $cur_row) if ($field['Field'] == $cur_row['Field']) {$flag=false; break;}
if ($flag) mysql_query("ALTER TABLE ".CATEGORIES_TABLE." ADD ".$field['Field']." ".$field['Type']." DEFAULT ".$field['Default']);
$q = db_query("select categoryID, name, products_count, products_count_admin, parent, picture, subcount, enable AS adm_enable FROM ".CATEGORIES_TABLE." ORDER BY sort_order, name");
5. в файле index.php
строку
$q = db_query("select categoryID, name, products_count, products_count_admin, parent, picture, subcount FROM ".CATEGORIES_TABLE." ORDER BY sort_order, name");
заменяем на
$q = db_query("select categoryID, name, products_count, products_count_admin, parent, picture, subcount, enable FROM ".CATEGORIES_TABLE." ORDER BY sort_order, name");
6. в файле pricelist.php в функции pricessCategories
строку
" where parent=".(int)$parent." order by sort_order, name");
меняем на
" where parent=".(int)$parent." AND enable=1 order by sort_order, name");