Manikandan
Manikandan

Reputation: 1816

How to get the current user id in prestashop version 1.5?

I am new to prestashop. I tried to develop a module. In that module I need the current user id for fetching details from the database. How do I get the current user id in prestashop 1.5?

Upvotes: 0

Views: 4684

Answers (4)

mebelkart com
mebelkart com

Reputation: 1

You can simply create a customer object and then call the customer id.

$customer = new Customer();
$customer_id = $customer->id;

Upvotes: -1

Vinaya Maheshwari
Vinaya Maheshwari

Reputation: 575

You can use global variable $cookie. It gives id of customer who is currently logged in.

global $cookie;
$user_id = $cookie->id_customer;

and then use $user_id to fetch details from database.

Upvotes: 0

AlexDeb
AlexDeb

Reputation: 157

You can get the current user id thanks to the context object :

$this->context->customer->id

You can find more example of how to use context object here : http://doc.prestashop.com/display/PS15/Using+the+Context+Object .

Upvotes: 4

romainberger
romainberger

Reputation: 4558

You can use $this->context->customer->id_customer. It will be empty if the user is not authenticated

Upvotes: 10

Related Questions