Aegidius Posted March 8, 2013 Share Posted March 8, 2013 (edited) Hello I created and installed a module and I can see it in the live edit position window, but it does not render any content. This is my module. <?php if (!defined('_PS_VERSION_')) { exit(); } require __DIR__ . '/DbManager.class.php'; class AdvancedSearchModule extends Module { public function __construct() { $this->name = 'advancedsearchmodule'; $this->tab = 'Search'; $this->version = 1.0; $this->author = 'Egidio Caprino'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Advanced Search'); $this->description = $this->l('Allow user to search for attributes.'); } public function install() { if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('displayHome')) { return false; } return true; } public function hookTop($params) { global $smarty; $smarty->assign('features', $this->getFeatures()); return $this->display(__FILE__, 'top.tpl'); } public function hookDisplayHome($params) { global $smarty; $features = $this->getFeatures(); $smarty->assign('features', $features); $this->display(__FILE__, 'home.tpl'); } public function uninstall() { if (!parent::uninstall()) { Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'advancedsearchmodule'); } parent::uninstall(); } private function getFeatures() { $lang = (int) $this->context->language->id; $db = DbManager::getInstance(); $query = 'SELECT id_feature, name FROM ' . _DB_PREFIX_ . 'feature_lang WHERE id_lang = ' . $lang . ' ORDER BY name ASC'; $result = $db->query($query); $features = array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $features[$row[0]] = array( 'name' => $row[1], 'values' => array() ); } $query = 'SELECT ' . _DB_PREFIX_ . 'feature_value.id_feature_value, ' . _DB_PREFIX_ . 'feature_value_lang.value FROM ' . _DB_PREFIX_ . 'feature_value INNER JOIN ' . _DB_PREFIX_ . 'feature_value_lang ON ' . _DB_PREFIX_ . 'feature_value.id_feature_value = ' . _DB_PREFIX_ . 'feature_value_lang.id_feature_value WHERE id_lang = ' . $lang . ' AND ' . _DB_PREFIX_ . 'feature_value.id_feature = %s ORDER BY ' . _DB_PREFIX_ . 'feature_value_lang.value ASC'; foreach ($features as $id_feature => $name) { $result = $db->query(sprintf($query, $id_feature)); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $features[$id_feature]['values'][$row[0]] = $row[1]; } } return $features; } } This is my home.tpl file placed in the same root of the file above. <h1> HOOK HOME </h1> Edited March 8, 2013 by Aegidius (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 8, 2013 Share Posted March 8, 2013 you can transplant module in modules -> position section? try it, maybe something doesnt work properly btw, which version of ps you use? Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 Actually, when I try to transplant the module on the homepage content (known as displayHome) it says that this module cannot be transplant this. I'm using the 1.5.3.1 version. Link to comment Share on other sites More sharing options...
vekia Posted March 8, 2013 Share Posted March 8, 2013 in installation function use: !$this->registerHook('top') !$this->registerHook('header') and create functions: public function hookHeader($params){} public function hookTop($params){} can you check it?? Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 I did it. I can transplant the module in the header and in the top. I cannot transplant it the center column (displayHome). I checked and the code under the hookDisplayHome function is executed. It just does not dysplay the home.tpl. This file is in the module dir. Is that position correct? I don't understand. Link to comment Share on other sites More sharing options...
vekia Posted March 8, 2013 Share Posted March 8, 2013 ok, so im checkin it on my localhost, wait a sec, i will try to debug this Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 Thank you. You are very nice Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 Have you found something? Link to comment Share on other sites More sharing options...
vekia Posted March 8, 2013 Share Posted March 8, 2013 try with this in installation: !$this->registerHook('home') and with this function: public function hookHome($params){} Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 I did it but it still not working. The code in that function is executed but the home.tpl is not diplayed. Is the problem in this line '$this->display(__FILE__, 'home.tpl');'? The home.tpl file is in the same directory of the module class. Link to comment Share on other sites More sharing options...
Aegidius Posted March 8, 2013 Author Share Posted March 8, 2013 I was missing the return. 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