0

I have a problem in my Magento 2.2.5 shop. I did the migration from magento 1.9.2.1

When I want to change the category from a product I get the next error: Unable to unserialize value.

The exception.log says

main.CRITICAL: Unable to unserialize value. {"exception":"[object] (InvalidArgumentException(code: 0): Unable to unserialize value. at /home/u53976p51115/domains/online-ledshop.be/public_html/vendor/magento/framework/Serialize/Serializer/Json.php:39)"}

I found a lot of solutions for this problem, Like change the Json.php file in vendor/magento/framework/Serialize/Serializer:

Change unserialize to

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;
}

And add this function:

function is_serialized($value, &$result = null)
{
    // Bit of a give away this one
    if (!is_string($value))
    {
        return false;
    }
    // Serialized false, return true. unserialize() returns false on an
    // invalid string or it could return false if the string is serialized
    // false, eliminate that possibility.
    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':
            // This looks odd but it is quicker than isset()ing
            $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;
}

But when I do this I get a 500 error on my website.

Can someone help me please?

  • if possible then please also share the sample response and the code which you are using to unserialize. – Ankit Srivastava Jun 8 at 5:43
  • Thank you for your reaction. I changed it. – NielN98 Jun 8 at 10:47
0

I found the problem.

There was something wrong in the url_rewrite database (metadata column). Probably wrong transferred during migration from 1.9.2.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.