Search code examples
prestashopprestashop-1.5

Prestashop custom tab in Back Office


I'm developing a module for prestashop 1.5.3. I need to create a custom admin tab during the module installation. I make the install like this

public function install()
{
    if( (parent::install() == false)||(!$this->_createTab())  )
        return false;
    return true;
}

And the _createTab method is:

private function _createTab()
{
    $tab = new Tab();
    $tab->id_parent = 7; // Modules tab
    $tab->class_name='AdminWarranty';
    $tab->module='fruitwarranty';
    $tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = $this->l('Warranty');
    $tab->active=1;
        if(!$tab->save()) return false;
return true;
}

And nothing happens.. What am I doing wrong.. and where to find good prestashop developer reference.?


Solution

  • To create a custom tab for a module during installation you can use the following code.

    Note: I am considering a test module called News.

    private function _createTab()
    {
        /* define data array for the tab  */
        $data = array(
                      'id_tab' => '', 
                      'id_parent' => 7, 
                      'class_name' => 'AdminNews', 
                      'module' => 'news', 
                      'position' => 1, 'active' => 1 
                     );
    
        /* Insert the data to the tab table*/
        $res = Db::getInstance()->insert('tab', $data);
    
        //Get last insert id from db which will be the new tab id
        $id_tab = Db::getInstance()->Insert_ID();
    
       //Define tab multi language data
        $data_lang = array(
                         'id_tab' => $id_tab, 
                         'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
                         'name' => 'News'
                         );
    
        // Now insert the tab lang data
        $res &= Db::getInstance()->insert('tab_lang', $data_lang);
    
        return true;
    
    } /* End of createTab*/
    

    I hope the above code will help Thanks