Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 599 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prestashop custom tab in Back Office

#1
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.?
Reply

#2
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
Reply

#3
Well, I'm myself developing a PrestaShop module so in case someone lands here, the proper way.

For root tabs:

$rootTab = new Tab();
$rootTab->active = 1;
$rootTab->class_name = 'YourAdminControllerName';
$rootTab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$rootTab->name[$lang['id_lang']] = $this->l("Root tab");
}
$rootTab->id_parent = 0; // No parent
$rootTab->module = $this->name;
$rootTab->add();

**Note for version 1.5:** When creating a root tab, the system will look for a YourAdminControllerName.gif in your module's folder as the tab icon. Also please note that root tabs don't work as links, despite them requiring a class_name.

For non-root tabs:

$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'YourAdminControllerName';
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = $this->l("Non-root tab");
}
$tab->id_parent = $rootTab->id; // Set the root tab we just created as parent
$tab->module = $this->name;
$tab->add();

If you want to set an existing tab as parent, you can use the getIdFromClassName function. For example, in your case:

$tab->id_parent = (int)Tab::getIdFromClassName('AdminModules');

The add() function returns false if it fails, so you can use it in the if() as you were trying to do with the save() function.

Sadly PrestaShop is by far the worst documented CMS system I've had to work with, and the only way to really code for it is reading code, so I hope it helps someone.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through