Jump to content

Module Hook Problem


swpierce

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...