alerax Posted February 5 Share Posted February 5 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 More sharing options...
AddWeb Solution Posted February 6 Share Posted February 6 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 More sharing options...
alerax Posted February 6 Author Share Posted February 6 (edited) 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 February 6 by alerax (see edit history) Link to comment Share on other sites More sharing options...
AddWeb Solution Posted February 6 Share Posted February 6 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 More sharing options...
alerax Posted February 6 Author Share Posted February 6 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now