简体   繁体   English

如何在Prestashop 1.6.1.3中获取用户ID会话

[英]How to get user id session in prestashop 1.6.1.3

the field name of user id is id_customer and I'm using prestashop 1.6.1.3 I already tried on this 用户ID的字段名称是id_customer,我正在使用prestashop 1.6.1.3,我已经对此进行过尝试

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

this 这个

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

this 这个

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

  echo $this->context->customer->id_customer;
}
else{
echo 'Not LoggedIn'; 
}

and this 和这个

   $id_customer = null;
    if ($this->context->customer->isLogged()) {
        // code to execute if i am logued
         $id_customer = $this->context->customer->id;
    }

but it's not working ..., can someone help me? 但它不起作用...,有人可以帮助我吗? thx 谢谢

*also if you have a tpl function to get id session, let me know. *另外,如果您有tpl函数来获取ID会话,请告诉我。

Instead of calling $this which depends of the controller / module you're working with. 而不是调用$this ,这取决于您正在使用的控制器/模块。 You can call directly the singleton Context object like this: 您可以像这样直接调用单例Context对象:

if (Context::getContext()->customer->id)
{
    $id_customer = Context::getContext()->customer->id;
}
else
{
    $id_customer = false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM