Wednesday, April 22, 2015

Adding a module front and admin controller in Prestashop 1.6

Recently I have started Prestashop module development for 1.6. Mine is a simple module to add SSO and another for adding custom fields to back-office order management. A process of the back-office order management will allow posting a cronjob. Anyway, the core part is, I needed to create a controller in the module (both front and admin controller). To add a module front controller create a file like /modules/<my_module>/controllers/front/<controller>.php. Then the class inside the front controller should look like this:

class <my_module><controller>FrontController extends ModuleFrontController

The route to this will be like <my_prestashop_host>/index.php?fc=module&module=<my_module>&controller=<controller
Also to create the back-office admin controller for you module create a file in /modules/<my_module>/controllers/admin/<controller>.php. The class definition should be:
class <controller>Controller extends ModuleAdminController
The route to this should look like <my_prestashop_host>/<admin_dir>/index.php?controller=<controllerThe most important part of the admin controller is Tab configuration. Make sure, in the install procedure of the module you register a tab something like this:

$tab = new Tab();
$tab->active = 1;
$tab->name = array();
$tab->class_name = '<controller>';


foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = '<my controller description text>';
}
$tab->id_parent = -1;
$tab->module = <my_module>;
$tab->add();

Make sure the record is there in ps_tab table.
Prestashop Themes Wordpress themes

No comments:

Post a Comment