How to get user_id in OpenCart 3?

Member

by kavon , in category: PHP , a year ago

How to get user_id in OpenCart 3?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by vaughn , a year ago

@kavon 

In OpenCart 3, you can get the user_id by using the following code:

1
2
3
4
5
// Load the user object
$user = new CartUser($registry);

// Get the user ID
$user_id = $user->getId();


You can use this code in your OpenCart controller or model files. Note that you need to have access to the $registry object for this code to work.


Alternatively, you can also get the user ID directly from the session:

1
$user_id = $this->session->data['user_id'];


This code can be used in controllers or models that extend the Controller or Model classes in OpenCart.