Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Prestashop current user id?

I used the below code to try to get the current user ID in prestashop.. am placing this code in another php file in my module directory and call it through by the module file.

 $id = $this->context->customer->id_customer;

but its not working for me.. am using prestashop 1.5 ..

like image 304
Manik Avatar asked Apr 26 '13 07:04

Manik


2 Answers

I certainly couldn't get it to work in my test either. However, you can try

$id = (int)$this->context->cookie->id_customer;

which works for me. I'm not at all sure that this is the best way to do it though.

like image 63
josephdietrich Avatar answered Sep 22 '22 23:09

josephdietrich


First check if user is logged in than get the id by $this->context->customer->id_customer

if ($this->context->customer->isLogged()) {

      echo $this->context->customer->id_customer;

}
else{
   echo 'Not LoggedIn';
}
like image 26
Raza Avatar answered Sep 19 '22 23:09

Raza