ralfillo 0 Posted April 11, 2016 (edited) Hi guys,I'm following a module creation book, however when I try to do addCss ( and JS ) in the CSS and the JS files don't appear in the <head>. This is the file mymodcomments.php <?php class MyModComments extends Module{ public function __construct(){ $this->name = 'mymodcomments'; $this->tab = 'front_office_features'; $this->version = '0.1'; $this->author = 'Just Me'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('My Module of product comments'); $this->description = $this->l('With this module, your customers will be able to grade and comments your products'); } public function processConfiguration(){ if (Tools::isSubmit('mymod_pc_form')){ $enable_grades = Tools::getValue('enable_grades'); $enable_comments = Tools::getValue('enable_comments'); Configuration::updateValue('MYMOD_GRADES', $enable_grades); Configuration::updateValue('MYMOD_COMMENTS', $enable_comments); $this->context->smarty->assign('confirmation', 'ok'); } } public function assignConfiguration() { $enable_grades = Configuration::get('MYMOD_GRADES'); $enable_comments = Configuration::get('MYMOD_COMMENTS'); $this->context->smarty->assign('enable_grades', $enable_grades); $this->context->smarty->assign('enable_comments', $enable_comments); } public function getContent(){ $this->processConfiguration(); $this->assignConfiguration(); return $this->display(__FILE__, 'getContent.tpl'); } public function install(){ parent::install(); $this->registerHook('displayProductTabContent'); return true; $this->registerHook('header'); } public function processProductTabContent(){ if (Tools::isSubmit('mymod_pc_submit_comment')){ $id_product = Tools::getValue('id_product'); $grade = Tools::getValue('grade'); $comment = Tools::getValue('comment'); $insert = array( 'id_product' => (int)$id_product, 'grade' => (int)$grade, 'comment' => pSQL($comment), 'date_add' => date('Y-m-d H:i:s'), ); Db::getInstance()->insert('mymod_comment', $insert); $this->context->smarty->assign('new_comment_posted', 'true'); } } public function assignProductTabContent(){ $enable_grades = Configuration::get('MYMOD_GRADES'); $enable_comments = Configuration::get('MYMOD_COMMENTS'); $id_product = Tools::getValue('id_product'); $comments = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'mymod_comment WHERE id_product = '.(int)$id_product); $this->context->controller->addCSS($this->_path . 'views/css/ mymodcomments.css', 'all'); $this->context->controller->addJS($this->_path . 'views/js/ mymodcomments.js'); $this->context->smarty->assign('enable_grades', $enable_grades); $this->context->smarty->assign('enable_comments', $enable_comments); $this->context->smarty->assign('comments', $comments); } public function hookDisplayProductTabContent($params){ $this->processProductTabContent(); $this->assignProductTabContent(); return $this->display(__FILE__, 'displayProductTabContent.tpl'); } } ?> I created both files (mymodcomments.css and mymodcomments.js) in the right path. I've been trying to fix this problem for hours but I can't find the solution, I'd really appreciate your help. Thanks! Edited April 11, 2016 by ralfillo (see edit history) Share this post Link to post Share on other sites
lexical_error 0 Posted April 11, 2016 (edited) hello i did it before as this way first add $this->registerHook('header') in public function install of ur module then add $this->context->controller->addJS($this->_path . 'views/js/ mymodcomments.js'); in public function hookHeader(). (for appear ur css or js in head) see blocktopmenu module for example. Edited April 11, 2016 by lexical_error (see edit history) Share this post Link to post Share on other sites
ralfillo 0 Posted April 11, 2016 Hi lexical_error, I just did the changes that you recommended me but it's still not working Do you have any other ideas? Thanks Share this post Link to post Share on other sites
lexical_error 0 Posted April 11, 2016 addcss and addjs should be in hookHeader function public function hookHeader() { $this->context->controller->addCSS($this->_path . 'views/css/ mymodcomments.css', 'all'); $this->context->controller->addJS($this->_path . 'views/js/ mymodcomments.js'); } Share this post Link to post Share on other sites
ralfillo 0 Posted April 12, 2016 Finally I coped most of the code from the repository from the book: https://github.com/FabienSerny/mymodcomments/commit/df34711810227e95177e07836b002d63530f0832 I adjusted it a bit and it works, it's a pity that I don't understand why wasn't working before <?php class MyModComments extends Module{ public function __construct(){ $this->name = 'mymodcomments'; $this->tab = 'front_office_features'; $this->version = '0.1'; $this->author = 'Just Me'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('My Module of product comments'); $this->description = $this->l('With this module, your customers will be able to grade and comments your products'); } public function install(){ parent::install(); $this->registerHook('displayProductTabContent'); return true; } public function processProductTabContent(){ if (Tools::isSubmit('mymod_pc_submit_comment')){ $id_product = Tools::getValue('id_product'); $grade = Tools::getValue('grade'); $comment = Tools::getValue('comment'); $insert = array( 'id_product' => (int)$id_product, 'grade' => (int)$grade, 'comment' => pSQL($comment), 'date_add' => date('Y-m-d H:i:s'), ); Db::getInstance()->insert('mymod_comment', $insert); $this->context->smarty->assign('new_comment_posted', 'true'); } } public function assignProductTabContent() { $enable_grades = Configuration::get('MYMOD_GRADES'); $enable_comments = Configuration::get('MYMOD_COMMENTS'); $id_product = Tools::getValue('id_product'); $comments = Db::getInstance()->executeS(' SELECT * FROM `'._DB_PREFIX_.'mymod_comment` WHERE `id_product` = '.(int)$id_product); $this->context->controller->addCSS($this->_path.'views/css/mymodcomments.css', 'all'); $this->context->controller->addJS($this->_path.'views/js/mymodcomments.js'); $this->context->smarty->assign('enable_grades', $enable_grades); $this->context->smarty->assign('enable_comments', $enable_comments); $this->context->smarty->assign('comments', $comments); } public function hookDisplayProductTabContent($params){ $this->processProductTabContent(); $this->assignProductTabContent(); return $this->display(__FILE__, 'displayProductTabContent.tpl'); } public function processConfiguration(){ if (Tools::isSubmit('mymod_pc_form')){ $enable_grades = Tools::getValue('enable_grades'); $enable_comments = Tools::getValue('enable_comments'); Configuration::updateValue('MYMOD_GRADES', $enable_grades); Configuration::updateValue('MYMOD_COMMENTS', $enable_comments); $this->context->smarty->assign('confirmation', 'ok'); } } } ?> Share this post Link to post Share on other sites
ialhamdazeez 0 Posted October 5, 2019 On 4/11/2016 at 2:41 PM, lexical_error said: hello i did it before as this way first add $this->registerHook('header') in public function install of ur module then add $this->context->controller->addJS($this->_path . 'views/js/ mymodcomments.js'); in public function hookHeader(). (for appear ur css or js in head) see blocktopmenu module for example. Thank you very much. I have the same book and get the same error. Now is the error resolved with your hint Share this post Link to post Share on other sites