获取用户ID Prestashop

获取用户ID Prestashop,prestashop,Prestashop,为什么即使登录,用户ID仍保持返回null?$params['cookie']->ID\u客户 而且您不应该使用全局变量。如果使用Prestashop 1.5,请使用上下文对象: function get_user_id() { global $cookie; $userid = NULL; if (isset($cookie->id_customer)) { $userid = $cookie->id_customer;

为什么即使登录,用户ID仍保持返回null?

$params['cookie']->ID\u客户


而且您不应该使用全局变量。

如果使用Prestashop 1.5,请使用
上下文
对象:

function get_user_id() 
{
    global $cookie;
    $userid = NULL;

    if (isset($cookie->id_customer))
    {
        $userid = $cookie->id_customer;
    }

    return $userid;
}


如果没有从父类继承的上下文。

您将此代码、创建的模块或控制器放在哪里?
$this->context->customer->id;
Context::getContext()->customer->id