Jump to content

[Solved] Get Current Employee ID


Thiago Quadros

Recommended Posts

Hi,
this is my last choice. I'm trying seek information in full internet.
Well, going to the question:
I'm trying get the ID of the current Employee logged. All method type, returned me a void sentence.
Example:
$_POST['id_employee']
$cookie->id_employee
and many others bad choices of codes.
Please, I'm needing help!

source code is in attachment.

tks...

ab_prod.php

Link to comment
Share on other sites

  • 1 year later...

I'm so glad it had worked ;)

 

 

Sorry for the old post, but I came accros it from Google, so, a better anwser :

 

Prestashop uses 2 cookies, one for Front and one for Backoffice. The backoffice cookie is named "psAdmin", encoded with a MD5 and contains the employee_id. So your solution is only working under /admin folder ! If you want to retrieve the employee_id outside it, you need to create a new Cookie('psAdmin')

Link to comment
Share on other sites

  • 9 months later...

Sorry for the old post, but I came accros it from Google, so, a better anwser :

 

Prestashop uses 2 cookies, one for Front and one for Backoffice. The backoffice cookie is named "psAdmin", encoded with a MD5 and contains the employee_id. So your solution is only working under /admin folder ! If you want to retrieve the employee_id outside it, you need to create a new Cookie('psAdmin')

 

Prestadget, i can't understand what you told about the backoffice cookie, can you please help us on how to use it ?

 

For now, i'm using the "global $cookie" and it's working

Link to comment
Share on other sites

  • 9 months later...
  • 2 months later...
  • 1 year later...
  • 1 month later...
  • 3 months later...
  • 1 year later...
  • 1 year later...
On 3/28/2016 at 9:53 AM, serfer2 said:

For Prestashop >= 1.5 you must use "Context" class (read the docs).

In example (inside a module code):


$employee_id = $this->context->employee->id; 

 

It's exactly the same in PrestaShop 1.7.

If you want to get the employee ID in a hook, you have to call it that way :

$id_employee = Context::getContext()->employee->id;

 

Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...
On 10/28/2019 at 4:54 AM, Pierre Belin said:

It's exactly the same in PrestaShop 1.7.

If you want to get the employee ID in a hook, you have to call it that way :

$id_employee = Context::getContext()->employee->id;

 

employee variable is 'NULL' while I'm a superAdmin Connected

Link to comment
Share on other sites

  • 1 year later...
On 1/13/2022 at 10:40 AM, ZiedDams said:

employee variable is 'NULL' while I'm a superAdmin Connected

Outside Prestashop You have to add admin cookie.

Use this code.

<?php

require_once dirname(__FILE__).'/config/config.inc.php';
$cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO'));

if (isset($cookie->id_employee) && $cookie->id_employee) {
    echo 'ID Employee: '.$cookie->id_employee;
} else {
    echo 'No employee logged in.';
}

 

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...