Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Location

Lyks's Achievements


Newbie (1/14)




Community Answers

  1. Hello, In order to add a tab to your backoffice, you can use the Tab object model. First you'll need to create your admin controller like so: /modules/your_module/controllers/admin/YourModuleNameController.php class YourModuleNameController extends ModuleAdminController { } Then to install automatically the tab when installing your module, add the following function in your main class: /modules/your_module/your_module_name.php class YourModuleName extends Module { /** ** [code...] */ public function installTab($parent_class, $class_name, $name) { $tab = new Tab(); // Define the title of your tab that will be displayed in BO $tab->name[$this->context->language->id] = $name; // Name of your admin controller $tab->class_name = $class_name; // Id of the controller where the tab will be attached // If you want to attach it to the root, it will be id 0 (I'll explain it below) $tab->id_parent = (int) Tab::getIdFromClassName($parent_class); // Name of your module, if you're not working in a module, just ignore it, it will be set to null in DB $tab->module = $this->name; // Other field like the position will be set to the last, if you want to put it to the top you'll have to modify the position fields directly in your DB return $tab->add(); } public function install() { return (parent::install() && $this->registerHook('backOfficeHeader') && $this->registerHook('displayTopColumn') && $this->registerHook('header') && // Then call this function here and only after parent::install // args: parent_classname ; current_classname ; tab_title // Note that you don't add the "Controller" suffix // In this example, the tab will be a subtab attached to the Catalog tab, which is attached to Sell, which is attached to the root $this->installTab('AdminCatalog', 'YourAdminClassName', 'My tab title') && Configuration::updateValue('MODULENAME', "ModuleName") ); } /** /** [...code] */ Don't forget to reinstall your module properly. Note that the tab will automatically be uninstalled. Now, what if you need to create a group of customs tabs with sub tabs inside of it : As you can see, you need a class for each tab you want to create. In the case you want to add a group of tabs like the default "SELL" tab in your BO, you'll have to create an abstract class that will define it, even if it does nothing. So let's create it like so : /override/controllers/admin/AdminYourClassNameController.php class AdminYourClassNameController extends AdminControllerCore { // to create this super tab, I recommand you to create a Tab object like before public function init() { $tab = new Tab(); $tab->name[$this->context->language->id] = "My Group of tabs"; $tab->class_name = "AdminYourClassName"; // This time we set the id to 0, which is the root $tab->id_parent = 0; $tab->add(); } } As we added a file in the override folder, don't forget to delete the class_index.php In Prestashop 1.7, you'll find it in /app/cache/dev/class_index.php Now, you have to execute once this controller in order to create its tab : https:://yourwebsite/your_admin_folder/index.php?controller=AdminYourControllerName
  • Create New...