Skip to content

Instantly share code, notes, and snippets.

@ircykk
Last active June 25, 2018 14:00
Show Gist options
  • Save ircykk/e2dd8ff1de590fc108db7923cf395584 to your computer and use it in GitHub Desktop.
Save ircykk/e2dd8ff1de590fc108db7923cf395584 to your computer and use it in GitHub Desktop.
PrestaShop Ps_CategoryTree Full tree
//...
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$category = new Category((int)Configuration::get('PS_HOME_CATEGORY'), $this->context->language->id);
if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') && isset($this->context->cookie->last_visited_category) && $this->context->cookie->last_visited_category) {
$category = new Category($this->context->cookie->last_visited_category, $this->context->language->id);
if (Configuration::get('BLOCK_CATEG_ROOT_CATEGORY') == 2 && !$category->is_root_category && $category->id_parent) {
$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);
}
}
/**
* In tpl.:
*
* {if $node.id|in_array:$parentList}aria-expanded="true"{/if}
*/
$currentCat = new Category((int)Tools::getValue('id_category'));
$parents = $currentCat->getParentsCategories();
$parentList = array();
foreach($parents as $parent) {
$parentList[] = $parent['id_category'];
}
return [
'categories' => $this->getCategories($category),
'currentCategory' => $category->id,
'parentList' => $parentList,
];
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment