Prestashop error: Trying to access array offset on value of type bool

Prestashop error: Trying to access array offset on value of type bool

我在我的 Prestashop 模块中开发了一个自定义页面。
我正在使用 Prestashop 1.7.7.2 和 PHP 7.4.
这是控制器代码:

class MymoduleConfirmemailModuleFrontController extends ModuleFrontController
{

    public $php_self = 'confirmemail';

    public function init()
    {
        parent::init();
    }

    public function initContent()
    {
        parent::initContent();
        $this->setTemplate('confirmemail');
    }

这是模板文件的代码:

{extends file='page.tpl'}

{block name='page_header_container'}{/block}

{block name='page_content'}
    <div>TEST</div>
{/block}

当我导航到相应的页面时,我收到以下错误:
注意:尝试访问 bool

类型值的数组偏移量

页面不显示。 如果我删除 {extends file='page.tpl'} 行,它会按预期显示“TEST”。

根据堆栈跟踪,经过一些调试后我发现问题出在 classes/Connection.php:

中的这些行中
[...]
$sql = 'SELECT SQL_NO_CACHE `id_guest`
        FROM `' . _DB_PREFIX_ . 'connections`
        WHERE `id_guest` = ' . (int) $cookie->id_guest . '
        AND `date_add` > \'' . pSQL(date('Y-m-d H:i:00', time() - 1800)) . '\'
        ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
        ORDER BY `date_add` DESC';
$result = Db::getInstance()->getRow($sql, false);
       
---> if (!$result['id_guest'] && (int) $cookie->id_guest) {
[...]

问题是查询 returns 为假,因为没有包含 ID 为 $cookie->id_guest 的 id_guest 的行,所以最后一行抛出错误。 我错过了什么?

您没有注意到 PS 1.7.7.2 与 PHP 7.4 不兼容:

https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/

降级到 7.3 应该可以解决这个问题。

我通过测试方法 getCoverWs return 是否有任何结果集解决了这个问题,如果不是 return false。我的代码是在 classes/Product.php

上更改为以下代码
public function getCoverWs()
{
    $result = $this->getCover($this->id);
    if (!$result) {
        return false;
    }
    return $result['id_image'];
}