Jump to content

Tool.php bug


alerax

Recommended Posts

Hello, after upgrade to PS 8.1 i'm getting an alert in php log

 

PHP Warning: Attempt to read property "id" on null in /home/xxxx/public_html/classes/Tools.php on line 1307

 

 /**
     * @param string $tab
     * @param Context $context
     *
     * @return bool|string
     */
    public static function getAdminTokenLite($tab, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }

        return Tools::getAdminToken($tab . (int) Tab::getIdFromClassName($tab) . (int) $context->employee->id);             <----- LINE 1307
    }

 

 

Any idea how to fix this issue? 

 

Thanks you for your help!

 

 

Quote

Link to comment
Share on other sites

Hi,

To fix this issue, you can modify your code to handle the potential null value returned by Tab::getIdFromClassName($tab)

$tabId = Tab::getIdFromClassName($tab);
if ($tabId !== null) {
    return Tools::getAdminToken($tab . (int) $tabId . (int) $context->employee->id);
} else {
	error_log("Error: Tab ID is null for tab '$tab'");
	return false; // Or any default value you want
}

I hope this would help!

Thanks.

Link to comment
Share on other sites

4 hours ago, AddWeb Solution said:

Hi,

To fix this issue, you can modify your code to handle the potential null value returned by Tab::getIdFromClassName($tab)

$tabId = Tab::getIdFromClassName($tab);
if ($tabId !== null) {
    return Tools::getAdminToken($tab . (int) $tabId . (int) $context->employee->id);
} else {
	error_log("Error: Tab ID is null for tab '$tab'");
	return false; // Or any default value you want
}

I hope this would help!

Thanks.

Hello thanks your for your reply. I don't understand how do you mean to change original code with your code. Do you mean to change all or add?

can explain me better?

thx

Original code

 

/**
     * @param string $tab
     * @param Context $context
     *
     * @return bool|string
     */
    public static function getAdminTokenLite($tab, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }

        return Tools::getAdminToken($tab . (int) Tab::getIdFromClassName($tab) . (int) $context->employee->id);             <----- LINE 1307
    }

Edited by alerax (see edit history)
Link to comment
Share on other sites

43 minutes ago, alerax said:

Hello thanks your for your reply. I don't understand how do you mean to change original code with your code. Do you mean to change all or add?

can explain me better?

thx

Original code

 

/**
     * @param string $tab
     * @param Context $context
     *
     * @return bool|string
     */
    public static function getAdminTokenLite($tab, Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }

        return Tools::getAdminToken($tab . (int) Tab::getIdFromClassName($tab) . (int) $context->employee->id);             <----- LINE 1307
    }

Hi,

In general, it is not recommended to directly modify core files, including classes/Tools.php. Instead, you need to override the logic using Prestashop override mechanism.

Thanks!

Link to comment
Share on other sites

6 hours ago, AddWeb Solution said:

Hi,

In general, it is not recommended to directly modify core files, including classes/Tools.php. Instead, you need to override the logic using Prestashop override mechanism.

Thanks!

Tried with override and also in core css but doesn't work, any different way?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...