I developed a custom page within my Prestashop module.
I'm using Prestashop 1.7.7.2 and PHP 7.4.
This is the Controller code:
class MymoduleConfirmemailModuleFrontController extends ModuleFrontController
{
public $php_self = 'confirmemail';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate('confirmemail');
}
This is the code of the template file:
{extends file='page.tpl'}
{block name='page_header_container'}{/block}
{block name='page_content'}
<div>TEST</div>
{/block}
When I navigate to corresponding page I receive the following error:
Notice: Trying to access array offset on value of type bool
And the page doesn't display.
If I remove the line {extends file='page.tpl'}
it displays as expected "TEST".
Following the stack trace, after some debug I found that the problem is in these lines inside 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) {
[...]
The problem is that the query returns false because there is no row containing an id_guest with id $cookie->id_guest
so the last line throws an error.
What am I missing?
You're missing that PS 1.7.7.2 is not compatible with PHP 7.4 yet :
See
https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/
Downgrading to 7.3 should fix the issue.