Steve Posted November 15, 2018 Share Posted November 15, 2018 Hey, I'm interested in making my own module for thirty bees, is there documentation available for that? Or should I use this page from PrestaShop? Thanks! Link to comment Share on other sites More sharing options...
datakick Posted November 15, 2018 Share Posted November 15, 2018 yep, that doc is a good start Link to comment Share on other sites More sharing options...
Traumflug Posted November 15, 2018 Share Posted November 15, 2018 PrestaShop documentation is still mostly right, if one ignores stuff for PS 1.5 and before. And there's this: http://jump-ing.com/traumflugs/writing_modules, very incomplete, still a number of useful tutorials. Two things: - File config.xml is no longer part of the module, it always gets created on demand now. - Back office modules should get implemented as controllers. Like described here: http://jump-ing.com/traumflugs/backofficemenu_entries Most modules still use their configuration page for their main user interface, which is no longer encouraged. Link to comment Share on other sites More sharing options...
Steve Posted November 16, 2018 Author Share Posted November 16, 2018 @traumflug Hey, Thanks for your reply. I'm currently following your guide containing information about adding controllers. But my controller tab still says controller not found. Here is MyModule.php 'fees.php' in my case ``` <?php if (!defined('TBVERSION_')) exit; class fees extends Module { const MAIN_CONTROLLER = 'AdminMy'; public function __construct() { $this->name = 'fees'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Stefan'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Fees'); $this->description = $this->l('Give extra fees to products'); $this->tb_versions_compliancy = '> 1.0.0'; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99'); } public function install() { $success = parent::install(); if ($success) { try { $tab = new Tab(); $tab->module = $this->name; $tab->class_name = static::MAIN_CONTROLLER; $tab->id_parent = Tab::getIdFromClassName('AdminPriceRule'); $langs = Language::getLanguages(); foreach ($langs as $lang) { $tab->name[$lang['id_lang']] = $this->l('Updater'); } $success = $tab->save(); } catch (Exception $e) { $success = false; } } return $success; } public function uninstall() { $success = true; $tabs = Tab::getCollectionFromModule($this->name); foreach ($tabs as $tab) { $success = $success && $tab->delete(); } return $success && parent::uninstall(); } } ``` Here is MyAdminController.php code (and yes I did put in in controllers/admin/AdminMyController.php): ``` <?php if (!defined('TBVERSION_')) { exit; } class AdminMyController extends ModuleAdminController { public function __construct() { $this->bootstrap = true; parent::__construct(); } public function initContent() { $this->page_header_toolbar_title = $this->l('My Controller'); parent::initContent(); } } ``` The tab is also named 'Updater' instead of 'My' like the screenshot from your tutorial btw, no idea if that matters though. Do you perhaps know why it doesn't work? Link to comment Share on other sites More sharing options...
Traumflug Posted November 16, 2018 Share Posted November 16, 2018 The controller needs to be in the right place: <module folder>/controllers/admin/. Else the PHP autoloader doesn't find it. And one has to delete cache/class_index.php in the shop installation after placing it. This file will get recreated on the next page request. If there's something missing in the description, don't hesitate to edit this wiki. Subscription is free and unrestricted, of course. Link to comment Share on other sites More sharing options...
Steve Posted November 19, 2018 Author Share Posted November 19, 2018 @traumflug That did it, thanks! Link to comment Share on other sites More sharing options...
Steve Posted November 19, 2018 Author Share Posted November 19, 2018 @traumflug I've another questions. Why is in the tab 'Price Rules' my module still called 'Updater'? I can't seem to fix that. I've changed const MAIN_CONTROLLER = 'AdminMy'; To: const MAIN_CONTROLLER = 'Fees'; And: $tab->name[$lang['id_lang']] = $this->l('Updater'); To: $tab->name[$lang['id_lang']] = $this->l('Fees'); But it still doesn't change te name? I already cleared the cache and I have deleted class_index.php but without luck. Thanks! (Here is all the code again if you need it) fees.php: ``` <?php if (!defined('TBVERSION_')) exit; class Fees extends Module { const MAIN_CONTROLLER = 'Fees'; public function __construct() { $this->name = 'fees'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Stefan'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Fees'); $this->description = $this->l('Give extra fees to products'); $this->tb_versions_compliancy = '> 1.0.0'; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99'); } public function install() { $success = parent::install(); if ($success) { try { $tab = new Tab(); $tab->module = $this->name; $tab->class_name = static::MAIN_CONTROLLER; $tab->id_parent = Tab::getIdFromClassName('AdminPriceRule'); $langs = Language::getLanguages(); foreach ($langs as $lang) { $tab->name[$lang['id_lang']] = $this->l('Fees'); } $success = $tab->save(); } catch (Exception $e) { $success = false; } } return $success; } public function uninstall() { $success = true; $tabs = Tab::getCollectionFromModule($this->name); foreach ($tabs as $tab) { $success = $success && $tab->delete(); } return $success && parent::uninstall(); } } ``` AdminMyController.php: ``` <?php if (!defined('TBVERSION_')) { exit; } class AdminMyController extends ModuleAdminController { public function __construct() { $this->bootstrap = true; parent::__construct(); } public function initContent() { $this->page_header_toolbar_title = $this->l('Controller - Fees'); parent::initContent(); } } ``` Link to comment Share on other sites More sharing options...
datakick Posted November 19, 2018 Share Posted November 19, 2018 you need to reset the module. The tab is created during module installation --> when you change installation related code, you need to reinstall the module Link to comment Share on other sites More sharing options...
Steve Posted November 19, 2018 Author Share Posted November 19, 2018 @datakick Makes sense haha! Thanks. 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