Domi91 Posted June 18, 2017 Share Posted June 18, 2017 (edited) Prestashop 1.7 Hi, I am searching how to add an entry to back office menu. In 1.6, with the administration / menu, it was easy to add an entry in back office menu. And now ? Don't find how to do. Thanks for help. Edited November 23, 2017 by Domi91 (see edit history) 1 Link to comment Share on other sites More sharing options...
bdesprez Posted July 19, 2017 Share Posted July 19, 2017 I have the same need …I have developed a module for PrestaShop 1.6 which add new entries in the menu. But when I want to display the page I have a permission error (on superAdmin user is quite ugly …) Link to comment Share on other sites More sharing options...
Lyks Posted November 23, 2017 Share Posted November 23, 2017 (edited) 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 Edited November 23, 2017 by Lyks (see edit history) 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now