0

我需要在外部 PHP 页面中显示 prestashop 客户 ID。

在官方文档http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development )

我找到了php代码:

如果您需要从非 PrestaShop 代码访问 PrestaShop cookie,您可以使用此代码:

    include_once('path_to_prestashop/config/config.inc.php');
    include_once('path_to_prestashop/config/settings.inc.php');
    include_once('path_to_prestashop/classes/Cookie.php');
    $cookie = new Cookie('ps'); // Use "psAdmin" to read an employee's cookie.

所以我尝试了:

include_once('config/config.inc.php');
include_once('config/settings.inc.php');
include_once('classes/Cookie.php');
$cookie = new Cookie('ps'); 
$id_client = $cookie->id_customer;
echo $id_client;

但什么都没有显示,我尝试了其他令牌,只有“date_add”有效

我的代码有什么问题?

4

1 回答 1

0

以下作品:

global $smarty;
global $cookie;
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

$cookie = new Cookie('ps'); 
$id_client = $cookie->id_customer;
echo $id_client;

include(dirname(__FILE__).'/footer.php');

我自己测试过。包括 id 和 firstname 在内的所有内容都有效。看来您不应该包含 classes/Cookie.php 文件。相反,将其替换为global $cookie确保更改包含文件的目录。

于 2013-04-19T17:42:17.017 回答