Skip to content

Instantly share code, notes, and snippets.

@W4U-TOURS
Forked from kpodemski/Tools.php
Created July 2, 2021 07:13
Show Gist options
  • Save W4U-TOURS/b95a47e8653b66a28a3d829d35dea792 to your computer and use it in GitHub Desktop.
Save W4U-TOURS/b95a47e8653b66a28a3d829d35dea792 to your computer and use it in GitHub Desktop.
Handling guests user in Token::getToken() in PrestaShop
<?php
public static function getToken($page = true, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
if (!Validate::isLoadedObject($context->customer)) {
$unique = $context->cookie->id_guest;
} else {
$unique = $context->customer->id.$context->customer->passwd;
}
$unique .= Tools::getRemoteAddr();
if ($page === true) {
return (Tools::encrypt($unique.$_SERVER['SCRIPT_NAME']));
} else {
return (Tools::encrypt($unique.$page));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment