We need get global cookie variable: global $cookie;
To check if user is logged in:
- refer to the cookie ”isLogged()”method
global $cookie; if(!$cookie->isLogged()) { echo 'Please login'; } else { echo 'Everything good'; }
Get user’s id:
- $cookie->id_customer
Get user’s first name:
- $cookie->customer_firstname
Get user’s surname:
- $cookie->customer_lastname
Get user’s email address:
- $cookie->email
Get a language id:
- $cookie->id_lang
Full sample:
global $cookie; if(!$cookie->isLogged()) { echo 'Please login'; exit; } else { echo 'Hi, ' . $cookie->customer_firstname. ' ' .$cookie->customer_lastname . '<br/>'; echo 'We contact to you: '. $cookie->email; }
how get default group of customer ?
Thanks
Hi,
you need to look at the user object, there should be.
where would i put this code? in the tpl file?
Hi,
this code you can use in php file. If you need display some data, you need send with smarty to tpl file.
Example:
PHP file – global $smarty; $smarty->assign(‘info’, $info);
tpl file – {$info}
We recommend that you open any module and see full example.
sorry so would i need to create a module for this?
so if i create a php file called customername.php and then put
global $cookie;
if(!$cookie->isLogged())
{
echo ‘Please login’;
exit;
}
else
{
echo ‘Hi, ‘ . $cookie->customer_firstname. ‘ ‘ .$cookie->customer_lastname . ”;
echo ‘We contact to you: ‘. $cookie->email;
}
PHP file – global $smarty; $smarty->assign(‘customername’, $customername);
tpl file – {$customername}
would that then send to a tpl file with customername?
Hi,
We suggested that you first looked into the basics of PHP and Smarty. Then it will be easier to understand Prestashop.
Hi there, thanks a lot for the info 😉
I was wondering how I could get the “phone” info of a logged user, to fill directly a field… any ideas ?
thanks in advance.
Alberto
Hi,
One of the options to get the information about the customer:
global $cookie;
$customer = new Customer((int)$cookie->id_customer);
$customerInfo = $customer->getAddresses((int)$cookie->id_lang);
print_r($customerInfo);
“phone” and “phone_mobile” array variables.
hi there, thank you for your help…
it helped me to build some moduls, thanks