mexique1 Posted February 26, 2012 Share Posted February 26, 2012 Hi, I'm trying to understand how to create module following 1.5's principles. For the front components, it's ok, an example can be found in the blocknewsletter module. But for the admin components, I can't get it to work ! What I want to achieve in the very end is add a tab entry in the menu and manage the module from there. My tab doesn't manage any ModelObject in particular so it's not I have added an admin tab, whichs does not extends AdminTab but ModuleAdminControllerCore. AFAIK it seems to work like this : - Create a controller following the naming convention Admin<tabName>Controller, in a file named <tabName>.php, in /controller/admin, in the module folder. - Create views in /views/admin/<tabName>/, in module folder. The default view name is "content" This renders the content.tpl template. But is this really intended to work like this ? I want to use multiple controllers in the same tab/module and make hyperlinks between them, how to do that ? It's confusing and the shipped modules don't help, their views are resolved in the admin/themes folder. Please help Link to comment Share on other sites More sharing options...
Raphaël Malié Posted February 27, 2012 Share Posted February 27, 2012 Hello, in order to create an admin controller in your module, please follow these steps : 1. Create a file controllers/admin/MyTab.php in your module with following code : class MyTabController extends ModuleAdminController {} 2. Add our tab in ps_tab table, you can create your tab like this in the install method : $tab = new Tab(); $tab->name = 'My Tab'; $tab->module = 'yourmodulename'; $tab->id_parent = 0; // Root tab $tab->add(); 3. Your tab will be available in the menu. 4. Now if you want to customize your tab, you can do it the same way as other admin controllers, please look admin classes in ~/controllers/admin/ folders. 5) If you want to override default views you can do it yourmodule/views/templates/admin/mytab/ folder. For example if ou want to override the view helpers/form/form.tpl you have to create a file yourmodule/views/templates/admin/mytab/helpers/form/form.tpl Regards 6 Link to comment Share on other sites More sharing options...
mexique1 Posted February 27, 2012 Author Share Posted February 27, 2012 Hey Raphael, Thank you for your answer. The code which adds the tab is the same as adding it via the UI, right ? Actually, I need to attach my tab under the "Preferences" section. The thing is, I have looked at AdminControllers, but can't understand how it is intended to work, apart if your tab is backed by an ObjectModel. The tab I want to build does not need to display a particular ObjectModel. For example, where am I supposed to write the controller code (say, retrieve parameters, do something, and assign view variables) ? In the initContent method ? Can you explain a little more about the /helpers folder ? Link to comment Share on other sites More sharing options...
absolutic Posted March 2, 2012 Share Posted March 2, 2012 I have some questions about modules also. If you don't mind I ask these questions here, because it would be convenient to have one topic about modules development. The first question: I want my module to create overrides for some core classes, is it one way for this purpose to copy overriding classes while the module is installed to override/classes directory or there is another way as well? How can I do overrides for templates of core admin controllers? I've found the possibility to create one more theme in admin/themes/mythemename and activate this theme from admin panel. Is that the only way? Link to comment Share on other sites More sharing options...
ezakimak Posted April 12, 2012 Share Posted April 12, 2012 Hi, Can you point where I can find these prestashop 1.5 principles ? Thanks Hi, I'm trying to understand how to create module following 1.5's principles. For the front components, it's ok, an example can be found in the blocknewsletter module. But for the admin components, I can't get it to work ! What I want to achieve in the very end is add a tab entry in the menu and manage the module from there. My tab doesn't manage any ModelObject in particular so it's not I have added an admin tab, whichs does not extends AdminTab but ModuleAdminControllerCore. AFAIK it seems to work like this : - Create a controller following the naming convention Admin<tabName>Controller, in a file named <tabName>.php, in /controller/admin, in the module folder. - Create views in /views/admin/<tabName>/, in module folder. The default view name is "content" This renders the content.tpl template. But is this really intended to work like this ? I want to use multiple controllers in the same tab/module and make hyperlinks between them, how to do that ? It's confusing and the shipped modules don't help, their views are resolved in the admin/themes folder. Please help Link to comment Share on other sites More sharing options...
Dev On Web Posted April 12, 2012 Share Posted April 12, 2012 Hello, Raphaël, I would be very interested in the process of adding a tab admin but this time not using a module, but using the controllers & overrides. I tried to add an admin controller, then a tab, but it returns me "controller" ... "not found" ... Link to comment Share on other sites More sharing options...
Raphaël Malié Posted April 12, 2012 Share Posted April 12, 2012 Hello, I don't understand your question, can you give me more details pls ? Regards Link to comment Share on other sites More sharing options...
Dev On Web Posted April 12, 2012 Share Posted April 12, 2012 I am now trying to add a tab in the admin without using a module. I create a new tab via "Admin / Tabs" and it appears fine. But it does not have a controller "x controller not found". What is the procedure? Create a module is it mandatory to add a tab? Thank you. Link to comment Share on other sites More sharing options...
mexique1 Posted April 12, 2012 Author Share Posted April 12, 2012 To do this I'm afraid you will need to extend the Controller class directly. Look at the Module*Controller constructor, it needs a module : public function __construct() { $this->module = Module::getInstanceByName(Tools::getValue('module')); if (!$this->module->active) Tools::redirect('index'); $this->page_name = 'module-'.$this->module->name.'-'.Dispatcher::getInstance()->getController(); parent::__construct(); } Link to comment Share on other sites More sharing options...
DrGren Posted April 23, 2012 Share Posted April 23, 2012 Hi mexique1, I tried precisely that but I cannot make it work (I get the same error as Dev On Web). I ask myself what is wrong in these steps: 1. - I create /controllers/admin/AdminCostCenterController.php like so: class AdminCostCenterControllerCore extends AdminController{} 2. I create /classes/CostCenter.php like class CostCenterCore extends ObjectModel{} 3. I create the overrides /override/classes/CostCenter.php and /override/controllers/admin/AdminCostCenterController.php as: class CostCenter extends CostCenterCore{} and class AdminCostCenterController extends AdminCostCenterControllerCore{} Got any idea? Link to comment Share on other sites More sharing options...
DrGren Posted April 23, 2012 Share Posted April 23, 2012 Hi mexique1, I tried precisely that but I cannot make it work (I get the same error as Dev On Web). I ask myself what is wrong in these steps: 1. - I create /controllers/admin/AdminCostCenterController.php like so: class AdminCostCenterControllerCore extends AdminController{} 2. I create /classes/CostCenter.php like class CostCenterCore extends ObjectModel{} 3. I create the overrides /override/classes/CostCenter.php and /override/controllers/admin/AdminCostCenterController.php as: class CostCenter extends CostCenterCore{} and class AdminCostCenterController extends AdminCostCenterControllerCore{} Got any idea? OK, I found the error in my case and that could be the problem also for Dev on Web: When adding the tab I named the class only CostCenter while it should be AdminCostCenter. Link to comment Share on other sites More sharing options...
Dev On Web Posted April 24, 2012 Share Posted April 24, 2012 Exactly, I found how to do but I did not think to return to this topic say ... Sorry! Link to comment Share on other sites More sharing options...
DrGren Posted April 24, 2012 Share Posted April 24, 2012 To sum up this thread (and I think that the moderator then can mark it as SOLVED): In order to create an ADMIN tab you should create 1. Example.php in /classes/ 2. AdminExampleController.php in /controllers/admin/ 3. a ps_example table 4. a tab Example in the admin interface. Here comes the working code: 1. The class: <?php class Example extends ObjectModel { public $id; public $name; public static $definition = array( 'table' => 'example', 'primary' => 'id_example', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), ), ); public static function getCompanies() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT e.`id_example`, c.`name` FROM `'._DB_PREFIX_.'example` c ORDER BY c.`name` ASC'); } } ?> 2. The Controller: <?php class AdminExampleControllerCore extends AdminController { public function __construct() { $this->table = 'example'; $this->className = 'Example'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fieldsDisplay = array( 'id_example' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Title'), 'width' => 130), ); parent::__construct(); } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Examples'), 'image' => '../img/admin/example.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title:'), 'name' => 'name', 'size' => 33, 'required' => true, 'desc' => $this->l('Example name'), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } 3. DB: CREATE TABLE IF NOT EXISTS `ps_example` ( `id_example` int(11) NOT NULL auto_increment, `name` varchar(128) character set utf8 NOT NULL, PRIMARY KEY (`id_example`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; 4: Add TAB: Note that in my case I don't use translations since the site will never be in any other language than italian. Check the small differences in, for instance, Contact.php and AdminContactsController.php for the code. Hope this will help someone. Best Regards Henrik 6 Link to comment Share on other sites More sharing options...
El Patron Posted September 14, 2012 Share Posted September 14, 2012 Hello, in order to create an admin controller in your module, please follow these steps : 1. Create a file controllers/admin/MyTab.php in your module with following code : class MyTabController extends ModuleAdminController {} 2. Add our tab in ps_tab table, you can create your tab like this in the install method : $tab = new Tab(); $tab->name = 'My Tab'; $tab->module = 'yourmodulename'; $tab->id_parent = 0; // Root tab $tab->add(); 3. Your tab will be available in the menu. 4. Now if you want to customize your tab, you can do it the same way as other admin controllers, please look admin classes in ~/controllers/admin/ folders. 5) If you want to override default views you can do it yourmodule/views/templates/admin/mytab/ folder. For example if ou want to override the view helpers/form/form.tpl you have to create a file yourmodule/views/templates/admin/mytab/helpers/form/form.tpl Regards This worked perfectly for a module upgrade to 1.5. Thanks 1 Link to comment Share on other sites More sharing options...
Raphaël Malié Posted September 15, 2012 Share Posted September 15, 2012 Nice I'm glad it helped ! Link to comment Share on other sites More sharing options...
kiransharma Posted September 18, 2012 Share Posted September 18, 2012 (edited) @DrGren Thankx for your post #13 Just one correction, Use $this->fields_list = array( insteadOf $this->fieldsDisplay = array( +1 for this. Edited September 18, 2012 by kiransharma (see edit history) Link to comment Share on other sites More sharing options...
Nick Fedchik Posted September 18, 2012 Share Posted September 18, 2012 DEFAULT CHARSET=latin1 I guess much better is DEFAULT CHARSET=utf8 Link to comment Share on other sites More sharing options...
acnet Posted September 19, 2012 Share Posted September 19, 2012 Thanks a lot for this thread, The new developer guide doesnt seem to be up to date, and it helped me a lot dealing with the new MVC features. May i ask how to display a template in this MVC module ? I'm trying to create a module based on AdminCustomerController . when i put : $this->display='myaction'; in a new method it looks in "themes" and "overrides" but not in my module directory . And it still loads the List view. I would just like to be able to display a custom view for a new method with the new coding style. (I've not been able to find any module with a MVC admin yet to learn from it, can you advise one ? ) Thanks a lot Link to comment Share on other sites More sharing options...
Nagraj Posted September 25, 2012 Share Posted September 25, 2012 (edited) To sum up this thread (and I think that the moderator then can mark it as SOLVED): In order to create an ADMIN tab you should create 1. Example.php in /classes/ 2. AdminExampleController.php in /controllers/admin/ 3. a ps_example table 4. a tab Example in the admin interface. Here comes the working code: 1. The class: <?php class Example extends ObjectModel { public $id; public $name; public static $definition = array( 'table' => 'example', 'primary' => 'id_example', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), ), ); public static function getCompanies() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT e.`id_example`, c.`name` FROM `'._DB_PREFIX_.'example` c ORDER BY c.`name` ASC'); } } ?> 2. The Controller: <?php class AdminExampleControllerCore extends AdminController { public function __construct() { $this->table = 'example'; $this->className = 'Example'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fieldsDisplay = array( 'id_example' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Title'), 'width' => 130), ); parent::__construct(); } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Examples'), 'image' => '../img/admin/example.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title:'), 'name' => 'name', 'size' => 33, 'required' => true, 'desc' => $this->l('Example name'), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } 3. DB: CREATE TABLE IF NOT EXISTS `ps_example` ( `id_example` int(11) NOT NULL auto_increment, `name` varchar(128) character set utf8 NOT NULL, PRIMARY KEY (`id_example`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; 4: Add TAB: Note that in my case I don't use translations since the site will never be in any other language than italian. Check the small differences in, for instance, Contact.php and AdminContactsController.php for the code. Hope this will help someone. Best Regards Henrik i'm able to display the content in the newly created tab but when i tries to edit the row it is not showing the detils int he edit page. Any idea??? Thank Nagraj Edited September 26, 2012 by n.nagraj321 (see edit history) 1 Link to comment Share on other sites More sharing options...
mohamadeffazuan Posted December 17, 2012 Share Posted December 17, 2012 Hi, I just found this topic and it's really helpful. Thanks to DrGren and others! 1 Link to comment Share on other sites More sharing options...
sharif854 Posted January 31, 2013 Share Posted January 31, 2013 (edited) i try to load tpl file in adminTab of my module but still if fail wooow prestashop why you don't have documention like joomla your code is hard for beginners thank god i read prestashop 1.4 some one write sample module that have admin and front i write this if i can load the tpl for mymodule admin but someone help me i read core of prestashop i set tpl file like mymoduleAdminController->getTemplatePath is said but is don't load and i don't have error Edited January 31, 2013 by sharif854 (see edit history) Link to comment Share on other sites More sharing options...
Codigonexo Posted February 4, 2013 Share Posted February 4, 2013 Hi! First of all, great job, this topic is great, I've been searching something like this for days. I'm newbie in PrestaShop module development, and all tutorials that I found are very basic, they don't talk about Tabs or Back Office functionalities. I've tried what DrGren said, but it is not effective in my case. I'm trying to create a module that associates products to 'deals', and I need a new Back Office Tab where I can add new deals. Ok, until here, it is simply. I have created the tab, and I can see it and access without errors... and without anything. It is blank, I can see the top menu, a huge blank space, and the footer, nothing more. I just did what DrGren said: the files contains the same code (obviously, adapted to my classes), the Controller goes into /controllers/admin/ folder, and the class goes into /classes folder (during the install, the module copies controller and class to their respective folders). Why I can not see anything? Thanks again! Link to comment Share on other sites More sharing options...
sharif854 Posted February 4, 2013 Share Posted February 4, 2013 you don't want to copy this i read the core and i'll try to write toturial for this section Link to comment Share on other sites More sharing options...
be_tnt Posted March 4, 2013 Share Posted March 4, 2013 (edited) 5) If you want to override default views you can do it yourmodule/views/templates/admin/mytab/ folder. For example if ou want to override the view helpers/form/form.tpl you have to create a file yourmodule/views/templates/admin/mytab/helpers/form/form.tpl Are you sure this part is working? I have tried to override the form.tpl for my module and it did not take into account my override. OK it works -> typo mistake in the name of "mytab" Edited March 4, 2013 by be_tnt (see edit history) Link to comment Share on other sites More sharing options...
sniff Posted March 30, 2013 Share Posted March 30, 2013 Hello. First of all: thank you guys for this step by step tutorial how to create new back-office functionality. I followed yours instructions and came across a problem. Maybe you could help me? When I create a tab (Administration --> Menus) whose parent is not 'Home' (but for example: Orders) it is displayed correctly. But if I choose Home as parent for my new tab, it is not appear. For 'big' tabs (which are supposed to have submenus) I have to write module also (and write this module name when creating a tab)? Cheers, Anna Link to comment Share on other sites More sharing options...
ajayks2u Posted April 11, 2013 Share Posted April 11, 2013 (edited) I created a new tab using the classes and controller folder. But where to create views for the module in prestashop 1.5. Currently it is showing only header and footer, content section is blank. From the discussion it is said to create "yourmodule/views/templates/admin/mytab/" folder where should we create this? Really confused with the display part . Can anyone help ????????????? Edited April 15, 2013 by ajayks2u (see edit history) Link to comment Share on other sites More sharing options...
Hippos Posted April 22, 2013 Share Posted April 22, 2013 I created a new tab using the classes and controller folder. But where to create views for the module in prestashop 1.5. Currently it is showing only header and footer, content section is blank. The same problem!!! Link to comment Share on other sites More sharing options...
NaveenYadav Posted May 24, 2013 Share Posted May 24, 2013 Hello All, I want to create form by extending AdminTab using helper class or any other . Please help me. Thanks Link to comment Share on other sites More sharing options...
NaveenYadav Posted May 24, 2013 Share Posted May 24, 2013 You must create the display function in the controller, When you write anything in this,It will show. Link to comment Share on other sites More sharing options...
Pradyuman Posted June 4, 2013 Share Posted June 4, 2013 Hello Friend, I want to add a Tab on admin panel. I am describing my requirements below: I have a module, I want to add a tab on admin panel . when I'll click on that tab at that time the module configuration page will open. Have you idea or Would you able to assist me? I am using Prestashop 1.5.0.17 So your guide should valid for Prestashop 1.5. Thank You Link to comment Share on other sites More sharing options...
NaveenYadav Posted June 4, 2013 Share Posted June 4, 2013 Hello Pradyuman, I have read your requirement and I am please to inform you that I have created exectly code which you want, Here is my code you read this and implement as your requirement. <?php if(!defined('_PS_VERSION_')) exit; class PrestashopTool extends Module { public function __construct() { $this->name = 'prestashoptool'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Naveen'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Prestashop tool'); $this->description = $this->l('This tool is to deign the t-shirt'); $path .= '/../modules/'.$this->name; } public function install() { $parent_tab = new Tab(); $parent_tab->name = 'Tool'; $parent_tab->class_name = 'AdminMainPrestashopTool'; $parent_tab->id_parent = 0; $parent_tab->module = $this->name; $parent_tab->add(); if (!parent::install() || !$this->registerHook('displayleftColumn') || !$this->registerHook('displayHeader') || !$this->installModuleTab('category', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Category'), $parent_tab->id) || !$this->installModuleTab('font_category', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Font Category'), $parent_tab->id) || !$this->installModuleTab('design_category', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Design Category'), $parent_tab->id) || !$this->installModuleTab('manage_row_product', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Row Product'), $parent_tab->id) || !$this->installModuleTab('manage_color', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Color'), $parent_tab->id) || !$this->installModuleTab('manage_font', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Font'), $parent_tab->id) || !$this->installModuleTab('manage_view', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage View'), $parent_tab->id) || !$this->installModuleTab('manage_main_product', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Main Product'), $parent_tab->id) || !$this->installModuleTab('manage_size', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Size'), $parent_tab->id) || !$this->installModuleTab('product_designers', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Product Designers'), $parent_tab->id) || !$this->installModuleTab('assign_main_product', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Assign Main Product'), $parent_tab->id) || !$this->installModuleTab('manage_bulk_discount', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'Manage Bulk Discount'), $parent_tab->id) || !$this->registerHook('displayrightColumn') || !$this->create_table()) return false; return true; } public function uninstall() { //$tabMain = new Tab((int)Tab::getIdFromClassName('AdminMainPrestashopTool')); //$tabMain->delete(); $this->unlinkCategoryImages(); $res = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tool_category`'); $res &= Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tool_category_lang`'); $res &= Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tool_font_category`'); $res &= Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'tool_font_category_lang`'); if (!$res || !parent::uninstall() || !$this->uninstallModuleTab('category') || !$this->uninstallModuleTab('font_category') || !$this->uninstallModuleTab('design_category') || !$this->uninstallModuleTab('manage_row_product') || !$this->uninstallModuleTab('manage_color') || !$this->uninstallModuleTab('manage_font') || !$this->uninstallModuleTab('manage_view') || !$this->uninstallModuleTab('manage_main_product') || !$this->uninstallModuleTab('manage_size') || !$this->uninstallModuleTab('product_designers') || !$this->uninstallModuleTab('assign_main_product') || !$this->uninstallModuleTab('manage_bulk_discount') || !$this->uninstallModuleTab('AdminMainPrestashopTool')) return false; return true; } private function create_table() { $res = true; $res .= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tool_category` ( `id` int(10) unsigned NOT NULL auto_increment, `categoryImage` varchar(250) NOT NULL, `id_shop` int(10) unsigned NOT NULL, `status` ENUM("0","1") NOT NULL DEFAULT "1", `position` varchar(100) NOT NULL, `isDefault` ENUM("0","1") NOT NULL DEFAULT "0", `addDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `modDate` TIMESTAMP NOT NULL, `isDeleted` ENUM("0","1") NOT NULL DEFAULT "0", PRIMARY KEY(`id`))'); $res .= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tool_category_lang` ( `catId` int(10) unsigned NOT NULL, `id_lang` int(10) NOT NULL, `CategoryName` varchar(255) NOT NULL)'); $res .= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tool_font_category` ( `id` int(10) unsigned NOT NULL auto_increment, `status` ENUM("0","1") NOT NULL DEFAULT "0", `id_shop` int(10) unsigned NOT NULL, `addDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `modDate` TIMESTAMP NOT NULL, `isDefault` ENUM("0","1") NOT NULL DEFAULT "0", `isDeleted` ENUM("0","1") NOT NULL DEFAULT "0", `sequence` int(10) NOT NULL, PRIMARY KEY(`id`))'); $res .= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'tool_font_category_lang` ( `fontcatId` int(10) unsigned NOT NULL, `id_lang` int(10) NOT NULL, `fontcategoryName` varchar(250) NOT NULL)'); return $res; } private function installModuleTab($tabClass, $tabName, $idTabParent) { $idTab = $idTabParent; $pass = true ; @copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$tabClass.'.gif'); $tab = new Tab(); $tab->name = $tabName; $tab->class_name = $tabClass; $tab->module = $this->name; $tab->id_parent = $idTab; $pass = $tab->save(); return($pass); } private function uninstallModuleTab($tabClass) { $pass = true ; $pass = true ; @unlink(_PS_IMG_DIR_.'t/'.$tabClass.'.gif'); $idTab = Tab::getIdFromClassName($tabClass); if($idTab != 0) { $tab = new Tab($idTab); $pass = $tab->delete(); } return($pass); } private function unlinkCategoryImages() { $r = Db::getInstance()->executeS('SELECT categoryImage FROM '._DB_PREFIX_.'tool_category'); if(!empty($r)) { foreach($r as $k=>$v) unlink($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.'prestashoptool/img/category/'.$v["categoryImage"]); } } } 1 Link to comment Share on other sites More sharing options...
mrranjeetmca Posted December 26, 2013 Share Posted December 26, 2013 (edited) ADMIN tab MVC module view controller dose not follow the fully MVC structure. You can add the admin panel a new tab function install(){ if (parent::install() == false){ return false; } if (!$id_tab) { $tab = new Tab(); if ($this->psversion()==5){ $tab->class_name = $this->tabClassName; } else { $tab->class_name = $this->tabClassName."14"; } $parent_tab = new Tab(); foreach (Language::getLanguages(true) as $lang) $parent_tab->name[$lang['id_lang']] = $this->displayName; $parent_tab->class_name = $this->tabClassName; $parent_tab->position = $this->position; $parent_tab->add(); $tab->id_parent = Tab::getIdFromClassName($this->tabClassName); $tab->module = $this->name; $languages = Language::getLanguages(); foreach ($languages as $language) $tab->name[$language['id_lang']] = $this->displayName; $tab->add(); } $sql= "CREATE TABLE `"._DB_PREFIX_."citycakeserviceclient` (`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , `service_type` INT(11), `date_add` datetime NOT NULL)"; if(!$result=Db::getInstance()->Execute($sql)) { //insert one data with default value return false; } return true; } so you can see if (!$id_tab) { $tab = new Tab();if ($this->psversion()==5){ $tab->class_name = $this->tabClassName;} else {$tab->class_name = $this->tabClassName."14";} $parent_tab = new Tab(); above section to add the tab during the module installation. you can see more in details mrphpguru.com Thanks Edited December 26, 2013 by mrranjeetmca (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted December 26, 2013 Share Posted December 26, 2013 ADMIN tab MVC module view controller dose not follow the fully MVC structure. You can add the admin panel a new tab function install(){ if (parent::install() == false){ return false; } if (!$id_tab) { $tab = new Tab(); if ($this->psversion()==5){ $tab->class_name = $this->tabClassName; } else { $tab->class_name = $this->tabClassName."14"; } $parent_tab = new Tab(); foreach (Language::getLanguages(true) as $lang) $parent_tab->name[$lang['id_lang']] = $this->displayName; $parent_tab->class_name = $this->tabClassName; $parent_tab->position = $this->position; $parent_tab->add(); $tab->id_parent = Tab::getIdFromClassName($this->tabClassName); $tab->module = $this->name; $languages = Language::getLanguages(); foreach ($languages as $language) $tab->name[$language['id_lang']] = $this->displayName; $tab->add(); } $sql= "CREATE TABLE `"._DB_PREFIX_."citycakeserviceclient` (`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY , `service_type` INT(11), `date_add` datetime NOT NULL)"; if(!$result=Db::getInstance()->Execute($sql)) { //insert one data with default value return false; } return true; } so you can see if (!$id_tab) { $tab = new Tab(); if ($this->psversion()==5){ $tab->class_name = $this->tabClassName; } else { $tab->class_name = $this->tabClassName."14"; } $parent_tab = new Tab(); above section to add the tab during the module installation. you can see more in details mrphpguru.com Thanks it's a copy of my code (from my modules) i don't allow to use it in any other modules. Link to comment Share on other sites More sharing options...
elham_K Posted August 25, 2014 Share Posted August 25, 2014 To sum up this thread (and I think that the moderator then can mark it as SOLVED): In order to create an ADMIN tab you should create 1. Example.php in /classes/ 2. AdminExampleController.php in /controllers/admin/ 3. a ps_example table 4. a tab Example in the admin interface. Here comes the working code: 1. The class: <?php class Example extends ObjectModel { public $id; public $name; public static $definition = array( 'table' => 'example', 'primary' => 'id_example', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), ), ); public static function getCompanies() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT e.`id_example`, c.`name` FROM `'._DB_PREFIX_.'example` c ORDER BY c.`name` ASC'); } } ?> 2. The Controller: <?php class AdminExampleControllerCore extends AdminController { public function __construct() { $this->table = 'example'; $this->className = 'Example'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fieldsDisplay = array( 'id_example' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Title'), 'width' => 130), ); parent::__construct(); } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Examples'), 'image' => '../img/admin/example.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title:'), 'name' => 'name', 'size' => 33, 'required' => true, 'desc' => $this->l('Example name'), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } 3. DB: CREATE TABLE IF NOT EXISTS `ps_example` ( `id_example` int(11) NOT NULL auto_increment, `name` varchar(128) character set utf8 NOT NULL, PRIMARY KEY (`id_example`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; 4: Add TAB: addtab.jpg Note that in my case I don't use translations since the site will never be in any other language than italian. Check the small differences in, for instance, Contact.php and AdminContactsController.php for the code. Hope this will help someone. Best Regards Henrik Hi , I did all of this steps but I have this error! I created class AdminExampleController in /controllers/admin but I don't understand why I have this error ! Could anyone help me please? ( ! ) Fatal error: Class 'AdminExampleController' not found in C:\wamp\www\Keshtgar\prestashop\classes\controller\Controller.php on line 135 Call Stack # Time Memory Function Location 1 0.0022 384272 {main}( ) ..\index.php:0 2 0.5456 8470448 DispatcherCore->dispatch( ) ..\index.php:54 3 0.6517 8860504 ControllerCore::getController( ) ..\Dispatcher.php:366 Link to comment Share on other sites More sharing options...
elham_K Posted September 1, 2014 Share Posted September 1, 2014 I find the solution, I delete class_index.php file in cache folder and It works now. Hi , I did all of this steps but I have this error! I created class AdminExampleController in /controllers/admin but I don't understand why I have this error ! Could anyone help me please? ( ! ) Fatal error: Class 'AdminExampleController' not found in C:\wamp\www\Keshtgar\prestashop\classes\controller\Controller.php on line 135 Call Stack # Time Memory Function Location 1 0.0022 384272 {main}( ) ..\index.php:0 2 0.5456 8470448 DispatcherCore->dispatch( ) ..\index.php:54 3 0.6517 8860504 ControllerCore::getController( ) ..\Dispatcher.php:366 Link to comment Share on other sites More sharing options...
DARKF3D3 Posted January 3, 2015 Share Posted January 3, 2015 To sum up this thread (and I think that the moderator then can mark it as SOLVED): In order to create an ADMIN tab you should create 1. Example.php in /classes/ 2. AdminExampleController.php in /controllers/admin/ 3. a ps_example table 4. a tab Example in the admin interface. Here comes the working code: 1. The class: <?php class Example extends ObjectModel { public $id; public $name; public static $definition = array( 'table' => 'example', 'primary' => 'id_example', 'multilang' => false, 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64), ), ); public static function getCompanies() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT e.`id_example`, c.`name` FROM `'._DB_PREFIX_.'example` c ORDER BY c.`name` ASC'); } } ?> 2. The Controller: <?php class AdminExampleControllerCore extends AdminController { public function __construct() { $this->table = 'example'; $this->className = 'Example'; $this->lang = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->fieldsDisplay = array( 'id_example' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Title'), 'width' => 130), ); parent::__construct(); } public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => $this->l('Examples'), 'image' => '../img/admin/example.gif' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title:'), 'name' => 'name', 'size' => 33, 'required' => true, 'desc' => $this->l('Example name'), ), ), 'submit' => array( 'title' => $this->l(' Save '), 'class' => 'button' ) ); return parent::renderForm(); } } 3. DB: CREATE TABLE IF NOT EXISTS `ps_example` ( `id_example` int(11) NOT NULL auto_increment, `name` varchar(128) character set utf8 NOT NULL, PRIMARY KEY (`id_example`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; 4: Add TAB: addtab.jpg Note that in my case I don't use translations since the site will never be in any other language than italian. Check the small differences in, for instance, Contact.php and AdminContactsController.php for the code. Hope this will help someone. Best Regards Henrik This will work also on PS1.6? Link to comment Share on other sites More sharing options...
smooglerpl Posted March 30, 2015 Share Posted March 30, 2015 *bump* What about icon? $parent_tab = new Tab(); $parent_tab->name[$this->context->language->id] = $this->l('boo foo'); $parent_tab->class_name = 'AdminControllerParentClassName'; $parent_tab->id_parent = 0; $parent_tab->module = $this->name; $parent_tab->add(); How to also set icon for tab? I can't find information about that. Link to comment Share on other sites More sharing options...
stathis Posted May 7, 2015 Share Posted May 7, 2015 *bump* What about icon? How to also set icon for tab? I can't find information about that. You will have to use css for that. Add a css file in mymodulename/css folder and then use a hook to load it: public function hookDisplayBackOfficeHeader() { $this->context->controller->addCSS($this->_path . 'css/mycssfile.css'); } Inside the css file you will have: .icon-AdminControllerParentClassName:before{ content: "\f019"; } Link to comment Share on other sites More sharing options...
Xander80 Posted May 24, 2015 Share Posted May 24, 2015 What I must edit? Where I must write text? In Example.php? Link to comment Share on other sites More sharing options...
mckaygerhard Posted August 11, 2017 Share Posted August 11, 2017 it's a copy of my code (from my modules) i don't allow to use it in any other modules. please! prestashop dont have good explained documentation, and 90% of the code and implemented software in prestashop are GPLv3/OSL! gime a break! Link to comment Share on other sites More sharing options...
jacky_risham Posted August 19, 2017 Share Posted August 19, 2017 Most importantly, extraordinary employment, this point is incredible, I've been hunting something like this down days. I'm a beginner in PrestaShop module improvement, and all instructional exercises that I found are extremely essential, they don't discuss Tabs or Back Office functionalities. I've attempted what Darren stated, however, it is not successful for my situation. I'm attempting to make a module that partners items to 'arrangements', and I require another Back Office Tab where I can include new arrangements. Alright, until here, it is essential. I have made the tab, and I can see it and access without blunders... what's more, without anything. It is clear, I can see the best menu, a gigantic clear space, and the footer, not much. I simply did what Darren stated: the documents contain a similar code (clearly, adjusted to my classes), the Controller goes into/controllers/administrator/envelope, and the class goes into/classes organizer (amid the introduce, the module duplicates controller and class to their individual envelopes). Why can I not see anything? Thanks Jacky Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 22, 2017 Share Posted September 22, 2017 i dont know if this help but i finally found how to do cleared with example code.. https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/ak0OuTuS9kU later i property set the relation between my module , my controller and my model: https://www.prestashop.com/forums/topic/623024-how-to-store-db-using-model-ad-canvas-example/?p=2614053 Link to comment Share on other sites More sharing options...
Recommended Posts