Jump to content

[SOLVED] How to create a new tab in the Back Office Modules page


justinl

Recommended Posts

Hello,

I'm creating a handful of modules for my own Prestashop install and I'm curious how to make a new organizational tab in the Modules page in the Back Office. Right now there are a whole bunch of tabs such as Search & Filter, Smart Shopping, SEO, Payment Security, and Front Office Features.

My question is how can I create my own tab to keep all my customized modules organized?

In the modules' config.xml and class files I have written in my own tab name (myTab, $this->tab = "myTab") but myTab doesn't show in the Back Office Modules list.

Any help would be greatly appreciated.

Link to comment
Share on other sites

make sure you have following rows in yourmodule.php:

public function __construct(){
......
       $this->tab = 'Admin';
       $this->tabClassName = 'YourModuleTabName';
       $this->tabParentName = 'AdminTools'; //in this example you add subtab under Tools tab. You may also declare new tab here
......
}

public function install(){
......
   if (!$id_tab) {
     $tab = new Tab();
     $tab->class_name = $this->tabClassName;
     $tab->id_parent = Tab::getIdFromClassName($this->tabParentName);
     $tab->module = $this->name;
     $languages = Language::getLanguages();
     foreach ($languages as $language)
       $tab->name[$language['id_lang']] = $this->displayName;
     $tab->add();
   }
.......
}

//Allow view access to anybody
public function viewAccess($disable = false){
       $result = true;
       return $result;
}

public function uninstall(){
....
   $id_tab = Tab::getIdFromClassName($this->tabClassName);
   if ($id_tab) {
     $tab = new Tab($id_tab);
     $tab->delete();
   }
....
}



Create file YourModuleTabName.php:

<?php
include(_PS_MODULE_DIR_.'yourmodule/yourmodule.php');

class YourModuleTabName extends AdminTab
{
 public function __construct()
 {
   $this->yourmodule = new yourModule();
   return parent::__construct();
 }

 public function display()
 {
   $this->yourmodule->token = $this->token;
   $this->yourmodule->displayMain(); //in displayMain() you have to place html form and all html elements you want to display on your tab
 }

}
?>



replace "yourmodule" and "YourModuleTabName" with real names

Due to the lack of documentation for developer I took this from another module and I recommend you to study some module too.

  • Like 4
Link to comment
Share on other sites

Ok! Figured this out on my own. Here's how to do it:

Open up admin/tabs/AdminModules.php

Inside the __construct() you'll see $this->listTabModule = array (...stuff...)
Inside that array are all of the different tabs. Simply add a new line in there with whatever you want your new module to be named e.g. 'myCustomTab' => $this->l('My Custom Tab'),

Tip: This new tab won't show up in the modules list unless there's a module assigned to the tab so just specify your new myCustomTab in your modules config.xml and class tab variable and you're all set!

Link to comment
Share on other sites

  • 1 month later...
make sure you have following rows in yourmodule.php:

replace "yourmodule" and "YourModuleTabName" with real names
...
...
Due to the lack of documentation for developer I took this from another module and I recommend you to study some module too.


Hi otzy.

I've seen your post about creating a new tab in AdminTab.

I'm wondering if it's possible to create a new tab in the product backend form through a module.
This is, just add a new tab with a specific form after attributes, features...

Another question, is there anyway of override prestashop functions ?
I need to develop a module which adds serial numbers to every product unit in stock, that's why I thought about tabs.
Obviously, the form must be checked if there some variation in stock.
I know that submitAddProduct in AdminProducts.php checks for required fields to be ok. So, could I add another check through module or do I need to change prestashop core ?

Thank you very much in advance.
Link to comment
Share on other sites

frankly, I am not a [spam-filter] of Prestashop.

Looking at AdminProducts.php I did not find any suitable hooks.

There is backOfficeFooter hook that you can use in back office. You can write javascript and add new tab with jQuery. When I experience the lack of hooks I use this way.

But as I can imagine this is only the part of the problem. You have to change order management and stock management too in order to get correct stock balance of serialized units.

Link to comment
Share on other sites

frankly, I am not a [spam-filter] of Prestashop.

Looking at AdminProducts.php I did not find any suitable hooks.

There is backOfficeFooter hook that you can use in back office. You can write javascript and add new tab with jQuery. When I experience the lack of hooks I use this way.

But as I can imagine this is only the part of the problem. You have to change order management and stock management too in order to get correct stock balance of serialized units.


Yeah, didn't think that!
Perhaps that could be a temporal solution until prestashop team release some developers reference manual.
Using that hook to inject javascript and change the behaviour of the buttons I need and. as you say, add a new tab with the form like others product tabs.
I'll have a look.

Thank you very much!
Link to comment
Share on other sites

  • 2 years later...

hello

 

to add new tab there it's necessary to change AdminModules controller. There is no other way. Otherwise - all modules with new tab will be listed in "Other tabs" tab.

 

open file: ADMIN_DIR/tabs/AdminModules.php

 

you've got there:

$this->listTabModules = array('administration' => $this->l('Administration'), 'advertising_marketing' => $this->l('Advertising & Marketing'),
		 'analytics_stats' => $this->l('Analytics & Stats'), 'billing_invoicing' => $this->l('Billing & Invoicing'), 'checkout' => $this->l('Checkout'),
		 'content_management' => $this->l('Content Management'), 'export' => $this->l('Export'), 'front_office_features' => $this->l('Front Office Features'),
		 'i18n_localization' => $this->l('I18n & Localization'), 'merchandizing' => $this->l('Merchandizing'), 'migration_tools' => $this->l('Migration Tools'),
		 'payments_gateways' => $this->l('Payments & Gateways'), 'payment_security' => $this->l('Payment Security'), 'pricing_promotion' => $this->l('Pricing & Promotion'),
		 'quick_bulk_update' => $this->l('Quick / Bulk update'), 'search_filter' => $this->l('Search & Filter'), 'seo' => $this->l('SEO'), 'shipping_logistics' => $this->l('Shipping & Logistics'),
		 'slideshows' => $this->l('Slideshows'), 'smart_shopping' => $this->l('Smart Shopping'), 'market_place' => $this->l('Market Place'), 'social_networks' => $this->l('Social Networks'), 'others'=> $this->l('Other Modules'));

add there own definition of new tab. for example "my fancy tab", code: 'my_fancy_tab' => $this->l('My fancy tab'), full code:

$this->listTabModules = array('my_fancy_tab' => $this->l('My fancy tab'), 'administration' => $this->l('Administration'), 'advertising_marketing' => $this->l('Advertising & Marketing'),
         'analytics_stats' => $this->l('Analytics & Stats'), 'billing_invoicing' => $this->l('Billing & Invoicing'), 'checkout' => $this->l('Checkout'),
         'content_management' => $this->l('Content Management'), 'export' => $this->l('Export'), 'front_office_features' => $this->l('Front Office Features'),
         'i18n_localization' => $this->l('I18n & Localization'), 'merchandizing' => $this->l('Merchandizing'), 'migration_tools' => $this->l('Migration Tools'),
         'payments_gateways' => $this->l('Payments & Gateways'), 'payment_security' => $this->l('Payment Security'), 'pricing_promotion' => $this->l('Pricing & Promotion'),
         'quick_bulk_update' => $this->l('Quick / Bulk update'), 'search_filter' => $this->l('Search & Filter'), 'seo' => $this->l('SEO'), 'shipping_logistics' => $this->l('Shipping & Logistics'),
         'slideshows' => $this->l('Slideshows'), 'smart_shopping' => $this->l('Smart Shopping'), 'market_place' => $this->l('Market Place'), 'social_networks' => $this->l('Social Networks'), 'others'=> $this->l('Other Modules'));

then in module (in construct function) you can use :

function __construct(){
...
$this->tab = 'my_fancy_tab';
...
}
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...