Jump to content

New Admin Tab - Bug


01generator

Recommended Posts

What I do in my module is usually create a new Tab for the particular module with it's own controller. 

 

Following code is what it is usually used.

public function installTab($parent, $class_name, $tab_name)
    {
        // Create new admin tab
        $tab = new Tab();
        $tab->id_parent = (int) Tab::getIdFromClassName($parent);
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
            $tab->name[$lang['id_lang']] = $tab_name;
        }

        $tab->class_name = $class_name;
        $tab->module = $this->name;
        $tab->active = 1;
        return $tab->add();
    }

Well in Prestashop 17 as you may know admin menu totally changed (not good for me as user experience totally changes and this has development and user experience drawbacks).

 

When I install a module that creates an admin tab as you see in the code you specify the parent admin tab menu that is going to be placed.

 

For example lets say that $parent = 'AdminPriceRule'; it is going to be placed under the Price Rules

In PS 17 this is not what is happening it creates a new category-title (css class name) like Sell, Improve and Configure and it is not a link!

 

Well any ideas, and if any knowledge to the subject to tell us how the new Tab() class works.

 

Cheers 

 

 

Link to comment
Share on other sites

  • 3 weeks later...

Nobody is facing the same issue? Am I the first?

To be honest I didn't search for the solution first but I though I wouldn't be the only facing it. 

 

Anyway sooner or later I will have to solve this, if I have news Ill be keeping you informed. 

 

If anyone has any info on the subject please share! 

Link to comment
Share on other sites

  • 7 months later...

Hello,

 

I have came up with a solution long ago but forgot to post it here. 

 

But better late than never (as we say in my country).

 

Well there are 2 differences in the classes/Tab.php file in public function add

 

1.6.X

public function add($autodate = true, $null_values = false)
    {
        // @retrocompatibility with old menu (before 1.5.0.9)
        $retro = array(
            'AdminPayment' => 'AdminParentModules',
            'AdminOrders' => 'AdminParentOrders',
            'AdminCustomers' => 'AdminParentCustomer',
            'AdminShipping' => 'AdminParentShipping',
            'AdminPreferences' => 'AdminParentPreferences',
            'AdminStats' => 'AdminParentStats',
            'AdminEmployees' => 'AdminAdmin',
        );

        $class_name = Tab::getClassNameById($this->id_parent);
        if (isset($retro[$class_name])) {
            $this->id_parent = Tab::getIdFromClassName($retro[$class_name]);
        }
        self::$_cache_tabs = array();

        // Set good position for new tab
        $this->position = Tab::getNewLastPosition($this->id_parent);
        $this->module = Tools::strtolower($this->module);

        // Add tab
        if (parent::add($autodate, $null_values)) {
            //forces cache to be reloaded
            self::$_getIdFromClassName = null;
            return Tab::initAccess($this->id);
        }
        return false;
    }

And in 1.7 

public function add($autoDate = true, $nullValues = false)
    {
        self::$_cache_tabs = array();

        // Set good position for new tab
        $this->position = Tab::getNewLastPosition($this->id_parent);
        $this->module = Tools::strtolower($this->module);

        // Add tab
        if (parent::add($autoDate, $nullValues)) {
            //forces cache to be reloaded
            self::$_getIdFromClassName = null;

            return Tab::initAccess($this->id);
        }

        return false;
    }

As you may notice it narrowed down. 

 

SO

 

in my public function installTab

 

You have to declare the $parent according to these

$retro = array(
            'AdminPayment' => 'AdminParentModules',
            'AdminOrders' => 'AdminParentOrders',
            'AdminCustomers' => 'AdminParentCustomer',
            'AdminShipping' => 'AdminParentShipping',
            'AdminPreferences' => 'AdminParentPreferences',
            'AdminStats' => 'AdminParentStats',
            'AdminEmployees' => 'AdminAdmin',
        );

Until now in 1.6 you had to pass the value AdminOrders if you wanted to be listed under the Order menu. 

In 1.7 instead of passing the value AdminOrders you pass the AdminParentOrders and thats it. :)

  • Like 2
Link to comment
Share on other sites

  • 11 months later...
  • Hi,

Looking at the Prestashop doc and the code of Prestashop 1.7.2.0,  I have successfully inserted a link to my module, link nested in the admin menu, section Configure. Please find below the 2 step process.

1. in modules/mymodule/mymodule.php, fonction __construct(), assign $this->tabs:
 

class MyModule extends Module
{

...

    public function __construct()
    {
    /*--Admin Menu--*/
    if (version_compare(_PS_VERSION_, '1.7.1', '>=')) {
        $this->tabs = array(
            array(
                'name' => 'Nom du Module',
                'class_name' => 'AdminMyModule',
                'parent_class_name' => 'CONFIGURE',
                'visible' => true,
            ));
    }

 

2. In modules/mymodule/controllers/admin, create a file named AdminMyModuleController.php :

if (!defined('_PS_VERSION_'))
    exit;

class AdminMyModuleController extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();

        if(!Tools::redirectAdmin('index.php?controller=AdminModules&token='.Tools::getAdminTokenLite('AdminModules').'&configure=nom_du_module_$this->name_dans__contruct')) {
            return false;
        }
        return true;
    }
}

Hope it will help you ... :)

Denis

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hey guys ,

just there is a point , I faced it and got soloution may be you need that ,

in prestashop 1.6 when we want to create a tab in root menu we should set id_parent=0 but in presta 1.7 we should do like following

        $name="Tab name";
        $tab = new Tab();
        $tab->id_parent=(int)Tab::getIdFromClassName('IMPROVE');
        $tab->name=array();
        foreach (Language::getLanguages(true) as $lang){
            $tab->name[$lang['id_lang']]=$name;
        }
        $tab->class_name='ClassNameOfThisModule';
        $tab->module=$this->name;
        $tab->active=1;
        $tab->add();

I hope this help you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...