add categories tree in module or controller in tpl


add categories tree Controller to tpl file

include class file: include('HelperTreeCategoriesBelvg.php');

$tree = new HelperTreeCategoriesBelvg('associated-categories-tree', 'Associated categories');
        $tree->setTemplate('tree_associated_categories.tpl')
        ->setHeaderTemplate('tree_associated_header.tpl')
        ->setRootCategory(Category::getRootCategory()->id)
        ->setUseCheckBox(false)
        ->setUseSearch(true);

 $this->context->smarty->assign(array(
    
            'category_tree' => $tree->render(),

        ));


//CLASS FILE HelperTreeCategoriesBelvg.php

<?php
class HelperTreeCategoriesBelvg extends HelperTreeCategories
{
    private $_part_selected_categories; // this is a new variable that displays only the categories that are NOT associated to all products included in the bulkAction.

    public function setPartSelectedCategories($value)
    {
        if (!is_array($value))
            throw new PrestaShopException('Selected categories value must be an array');

        $this->_part_selected_categories = $value;
        return $this;
    }

    public function getPartSelectedCategories()
    {
        if (!isset($this->_part_selected_categories))
            $this->_part_selected_categories = array();

        return $this->_part_selected_categories;
    }

    public function render($data = NULL)
    {
        $this->setAttribute('part_selected_categories', $this->getPartSelectedCategories());
        return parent::render($data);
    }
}

Comments

Popular Posts