Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

[*] blockcategories: display only part of tree starting on specified level #9

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions blockcategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function install()
!$this->registerHook('actionAdminLanguagesControllerStatusBefore') ||
!$this->registerHook('displayBackOfficeCategory') ||
!Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) ||
!Configuration::updateValue('BLOCK_CATEG_START_DEPTH', 1) ||
!Configuration::updateValue('BLOCK_CATEG_DHTML', 1) ||
!Configuration::updateValue('BLOCK_CATEG_ROOT_CATEGORY', 1))
return false;
Expand All @@ -88,6 +89,7 @@ public function uninstall()

if (!parent::uninstall() ||
!Configuration::deleteByName('BLOCK_CATEG_MAX_DEPTH') ||
!Configuration::deleteByName('BLOCK_CATEG_START_DEPTH') ||
!Configuration::deleteByName('BLOCK_CATEG_DHTML') ||
!Configuration::deleteByName('BLOCK_CATEG_ROOT_CATEGORY'))
return false;
Expand All @@ -100,6 +102,7 @@ public function getContent()
if (Tools::isSubmit('submitBlockCategories'))
{
$maxDepth = (int)(Tools::getValue('BLOCK_CATEG_MAX_DEPTH'));
$startDepth = max(1, (int)(Tools::getValue('BLOCK_CATEG_START_DEPTH')));
$dhtml = Tools::getValue('BLOCK_CATEG_DHTML');
$nbrColumns = Tools::getValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', 4);
if ($maxDepth < 0)
Expand All @@ -109,6 +112,7 @@ public function getContent()
else
{
Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', (int)$maxDepth);
Configuration::updateValue('BLOCK_CATEG_START_DEPTH', (int)$startDepth);
Configuration::updateValue('BLOCK_CATEG_DHTML', (int)$dhtml);
Configuration::updateValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', (int)$nbrColumns);
Configuration::updateValue('BLOCK_CATEG_SORT_WAY', Tools::getValue('BLOCK_CATEG_SORT_WAY'));
Expand Down Expand Up @@ -189,6 +193,13 @@ public function hookLeftColumn($params)
$category = new Category($category->id_parent, $this->context->language->id);
elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 3 && !$category->is_root_category && !$category->getSubCategories($category->id, true))
$category = new Category($category->id_parent, $this->context->language->id);
elseif (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 4 && !$category->is_root_category)
{
$start_at_depth = (int)Configuration::get('BLOCK_CATEG_START_DEPTH');
$starting_category_id = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_category` FROM `'._DB_PREFIX_.'category` WHERE `nleft` < '.pSQL((int)$category->nleft).' AND `nright` > '.pSQL((int)$category->nright).' AND `level_depth` = '.pSQL($start_at_depth));
if ($starting_category_id)
$category = new Category($starting_category_id, $this->context->language->id);
}
}
else
$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
Expand Down Expand Up @@ -407,6 +418,11 @@ public function renderForm()
'value' => 3,
'label' => $this->l('Current category, unless it has no subcategories, then parent one')
),
array(
'id' => 'current_top_parent',
'value' => 4,
'label' => $this->l('Current category top parent')
),
)
),
array(
Expand All @@ -415,6 +431,12 @@ public function renderForm()
'name' => 'BLOCK_CATEG_MAX_DEPTH',
'desc' => $this->l('Set the maximum depth of category sublevels displayed in this block (0 = infinite).'),
),
array(
'type' => 'text',
'label' => $this->l('Starting depth'),
'name' => 'BLOCK_CATEG_START_DEPTH',
'desc' => $this->l('Set the starting depth of category sublevels displayed in this block (0 = infinite).'),
),
array(
'type' => 'switch',
'label' => $this->l('Dynamic'),
Expand Down Expand Up @@ -502,6 +524,7 @@ public function getConfigFieldsValues()
{
return array(
'BLOCK_CATEG_MAX_DEPTH' => Tools::getValue('BLOCK_CATEG_MAX_DEPTH', Configuration::get('BLOCK_CATEG_MAX_DEPTH')),
'BLOCK_CATEG_START_DEPTH' => Tools::getValue('BLOCK_CATEG_START_DEPTH', Configuration::get('BLOCK_CATEG_START_DEPTH')),
'BLOCK_CATEG_DHTML' => Tools::getValue('BLOCK_CATEG_DHTML', Configuration::get('BLOCK_CATEG_DHTML')),
'BLOCK_CATEG_NBR_COLUMN_FOOTER' => Tools::getValue('BLOCK_CATEG_NBR_COLUMN_FOOTER', Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER')),
'BLOCK_CATEG_SORT_WAY' => Tools::getValue('BLOCK_CATEG_SORT_WAY', Configuration::get('BLOCK_CATEG_SORT_WAY')),
Expand Down