Jump to content

Session is not started in Hook


Recommended Posts

Hi,

I'm currently developing a module for tracking and showing ML-based recommendations on Product detail view. For this i need the session of a user in the template. I use the displayFooterProduct Hook. The problem is that when I'm directly accessing the product page, the session seems not to be started when the hook gets called. 

My Code: 

public function hookDisplayFooterProduct(array $params)
    {
        if (isset($params['product'])) {
            $id = $params['product']['id_product'];
            $this->context->smarty->assign('id_product', $id);
            $this->context->smarty->assign('session_id', $_COOKIE["PHPSESSID"] ?: session_id());
            $this->context->smarty->assign('user_id', (int)$this->context->cookie->id_customer);
            return $this->fetch('module:awseventtracking/views/templates/hook/product_pixel.tpl');
        }
        return null;
    }

This results in an error when directly accessing the Product detail view (without being on the page previously), because the PHPSESSID is undefined in the Cookie Array. session_id() is also null on this point. 

 

Can anyone provide help for this issue - what can i do to retrieve the Sessionvalue in the Hook? I'm in a Prestashop 1.7.6.7

 

Thanks

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...