Jump to content

Customer info in header.tpl and JS


Tally25

Recommended Posts

Hello,

I am a newbie in Prestashop development and I need to get the customer information and use it in header.tpl.

 

More specific, I need to get that information like the customer ID and if the customer is logged in and pass it to a script for tracking. It doesn't seem to work if I just add something like a variable I created in FrontController and smarty assign it.

Moreover, no errors occur, but the variable is empty. I am using Prestashop 1.6.1.13.

 

Any help regarding how to use variables in header.tpl or customer information inside <head> in header.tpl is greatly appreciated.

Thank you!

Edited by Tally25
Forgot to specify what Prestashop version I am using (see edit history)
Link to comment
Share on other sites

Share the code which you have used?

You need to assign the smarty variable in classes/controller/FrontController.php

At line number 486, INSERT the following lines.

 

if ($this->context->cookie->logged) {
	$custom_var['id'] = $this->context->cookie->id_customer;
	$custom_var['email'] = $this->context->cookie->email;
} else {
	$custom_var['id'] = 0;
	$custom_var['email'] = '';
}
$this->context->smarty->assign(array(
	'custom_var' => $custom_var
));

 

AND in the tpl file access the email & id using the line like {$custom_var['email']}. Hope it will help.

 

Kindly note that, Any modification in the core file is not recommended. 

 

 

  • Like 1
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...