diff --git a/blockcategories.php b/blockcategories.php index 5a9f524..f612b4a 100644 --- a/blockcategories.php +++ b/blockcategories.php @@ -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; @@ -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; @@ -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) @@ -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')); @@ -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); @@ -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( @@ -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'), @@ -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')),