Forked from manojind/Solved Unable to Unserialize Value” in Magento 2.2.5
Created
September 4, 2018 07:04
-
-
Save ritaxit/7717c38b6777e0d22ede17eb060f2e1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROOT directory | |
1. public_html/vendor/magento/framework/Serialize/Serializer/Json.php | |
2. Just replace below fucntion (unserialize) and add new function OR just download attached file and replace with default | |
public function unserialize($string) | |
{ | |
if($this->is_serialized($string)) | |
{ | |
$string = $this->serialize($string); | |
} | |
$result = json_decode($string, true); | |
if (json_last_error() !== JSON_ERROR_NONE) { | |
throw new \InvalidArgumentException('Unable to unserialize value.'); | |
} | |
return $result; | |
} | |
3. Add new function : | |
function is_serialized($value, &$result = null) | |
{ | |
if (!is_string($value)) | |
{ | |
return false; | |
} | |
if ($value === 'b:0;') | |
{ | |
$result = false; | |
return true; | |
} | |
$length = strlen($value); | |
$end = ''; | |
switch ($value[0]) | |
{ | |
case 's': | |
if ($value[$length - 2] !== '"') | |
{ | |
return false; | |
} | |
case 'b': | |
case 'i': | |
case 'd': | |
$end .= ';'; | |
case 'a': | |
case 'O': | |
$end .= '}'; | |
if ($value[1] !== ':') | |
{ | |
return false; | |
} | |
switch ($value[2]) | |
{ | |
case 0: | |
case 1: | |
case 2: | |
case 3: | |
case 4: | |
case 5: | |
case 6: | |
case 7: | |
case 8: | |
case 9: | |
break; | |
default: | |
return false; | |
} | |
case 'N': | |
$end .= ';'; | |
if ($value[$length - 1] !== $end[0]) | |
{ | |
return false; | |
} | |
break; | |
default: | |
return false; | |
} | |
if (($result = @unserialize($value)) === false) | |
{ | |
$result = null; | |
return false; | |
} | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment