Magento 2 Data Migration Edit Product Unable to unserialize value

烈酒焚心 提交于 2020-01-07 04:36:14

问题


I migrated magento site from 1.7.0.2 to 2.2 clean install. Migration completed without issues.

However if I attempt to edit a product or add a new product magento displays an error:

Unable to unserialize value.

Does anyone know what im doing wrong here?

Customers, categories and custom attributes all migrated without issue


回答1:


The problem is in /vendor/magento/framework/Serialize/Serializer/Json.php

There is a function unserialize($string) which gives you a syntax error if a string is serialized (not json but php serialization).

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 function to check if string is serialized:

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':
            // 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;
}

After doing this you solve your problem.




回答2:


I ran into this problem when doing the migration from 1.9.2.0 to 2.3.2. My additional_information in table sales_payment_transaction was empty. The error occurs in class Migration\Handler\SerializeToJson in method handle in string number 73: $unserializeData = unserialize($value); I made preference for this class and changed unserialize() function to json_decode().



来源:https://stackoverflow.com/questions/46725652/magento-2-data-migration-edit-product-unable-to-unserialize-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!