I used the code below to try to get the current user id in prestashop. I put this code in another php file in my module directory and call it through the module file.
$id = $this->context->customer->id_customer;
but it does not work for me .. i am using prestashop 1.5 ..
I also could not get it to work in my test. However you can try
$id = (int)$this->context->cookie->id_customer;
which works for me. I'm not sure if this is the best way to do this though.
First check if the user is registered, than get the identifier $this->context->customer->id_customer
$this->context->customer->id_customer
if ($this->context->customer->isLogged()) { echo $this->context->customer->id_customer; } else{ echo 'Not LoggedIn'; }
You cannot use cookies.
Just use this:
$id=(int)$this->context->customer->id;
you can remove (int), but I like to specify the content type im get.
BR's
In Prestashop 1.6, it is best to use a controller:
$id_customer = null; if ($this->context->customer->isLogged()) { // code to execute if i am logued $id_customer = $this->context->customer->id; }
Source: https://habr.com/ru/post/943682/More articles:admin.logentry: "user" refers to the model , which is either not installed or is abstract - djangoHow to include a mutable free file in WiX burn? - wixHow to make checkbox check by default in yii when using a single form to create and update - formsWhat is the reason the setAccessible method of the AccessibleObject class has a boolean parameter? - javaTrigger interaction before selectionChanged of ListPicker in Windows Phone 8 - windows-phoneNeed a link to open-source platforms based on scala applications - scalaHow to check undefined values ββin IE8? - javascriptSublime Text 2 Adding 1 column to another - appendIs it good to print / write in global object constructor or undefined behavior? - c ++Split an array into an additional array in Ruby - pythonAll Articles