2016-06-08 67 views
0

用戶ID的字段名稱是id_customer和我使用的Prestashop 1.6.1.3 我已經嘗試過這個如何獲得的Prestashop用戶ID會話1.6.1.3

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

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

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

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

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

但它不工作...,有人可以幫助我嗎? thx

*如果你有一個tpl函數來獲得id會話,請告訴我。

+0

:您可以直接調用單Context對象這樣的'$這個 - >上下文>客戶 - > ID;'你可以轉儲'$這個 - >上下文> customer' OT甚至' $ this-> context'或'$ this' – 2016-06-08 02:15:53

+0

@Dagon是這樣的嗎? $ id = $ this-> context-> customer-> id; echo $ id; –

+0

不問,如果你可以測試它。 – 2016-06-08 02:18:00

回答

0

而不是調用$this,這取決於您正在使用的控制器/模塊。也許

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