swpierce Posted May 5, 2014 Share Posted May 5, 2014 I'm teaching myself Prestashop. I've written a module that works great except for one problem I cannot figure out. The hook function never sets any data in the hook variable. Here's the code: class hkBlockDisplayCategories extends Module { public function __construct() { $this->name = 'hkBlockDisplayCategories'; $this->tab = 'front_office_features'; $this->version = 0.1; $this->author = 'Me'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Category Dsp Module'); $this->description = $this->l('Displays a list of categories available'); } public function install() { if (!parent::install()) { return false; } if (!$this->registerHook('home')) { return false; } return true; } public function hookHome($params) { global $smarty, $cookie, $link; $id_customer = (int)$params['cookie']->id_customer; $id_group = $id_customer ? Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_lang = (int)$params['cookie']->id_lang; $result = DB::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.*, cl.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) WHERE level_depth > 1 AND level_depth < 3 AND c.`active` = 1 AND cg.`id_group` = '.$id_group.' ORDER BY `level_depth` ASC, c.`position` ASC'); $category = new Category(1); global $link; $this->context->smarty->assign(array('categories' => $result, Category::getRootCategories(intval($params['cookie']->id_lang), true), 'link' => $link)); $this->context->smarty->assign(array('category' => $category,'lang' => Language::getIsoById(intval($params['cookie']->id_lang)),)); //return $this->display(__FILE__, 'hkBlockDisplayCategories.tpl'); return "Hello, world!"; } } I initially thought the template file might be the problem so I changed it to just return some text. Regardless of what I put in the return, $HOOK_HOME always gets set to the value 1. I added Logger statements (taken out for this post) so I know that everything works down to setting the data in the $HOOK_HOME variable. Please help? Thanks! Link to comment Share on other sites More sharing options...
Rolige Posted May 5, 2014 Share Posted May 5, 2014 Maybe you will never see anything with: return "Hello, world!";You need comment or delete: return "Hello, world!";And uncomment: return $this->display(__FILE__, 'hkBlockDisplayCategories.tpl');For test purposes, create the file "hkBlockDisplayCategories.tpl" in root of the module, and add some test lines inside. regards Link to comment Share on other sites More sharing options...
vekia Posted May 5, 2014 Share Posted May 5, 2014 to check if hook works, you can use there print_r("hello world"); then if hook (module hook) is executed properly you will see hello world text at the header section of your website. Link to comment Share on other sites More sharing options...
swpierce Posted May 5, 2014 Author Share Posted May 5, 2014 Thanks Vekia! print_r("hello world"); <= worked great Turns out I was missing a $ {HOOK_HOME} doesn't work as well as {$HOOK_HOME} Thanks again! 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