Magento 2.2.1 Không thể tuần tự hóa giá trị


12

Tôi đã nâng cấp trang web từ 2.1.6 lên 2.2.1 và phải đối mặt với việc không thể tuần tự hóa lỗi giá trị trong giao diện và phụ trợ.

{"0":"Unable to serialize value.","1":"#0 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Translate.php(494): Magento\\Framework\\Serialize\\Serializer\\Json->serialize(Array)\n
#1 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Translate.php(190): Magento\\Framework\\Translate->_saveCache()\n
#2 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Area.php(244): Magento\\Framework\\Translate->loadData(NULL, false)\n
#3 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Area.php(215): Magento\\Framework\\App\\Area->_initTranslate()\n
#4 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Area.php(142): Magento\\Framework\\App\\Area->_loadPart('translate')\n
#5 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/View\/DesignLoader.php(55): Magento\\Framework\\App\\Area->load('translate')\n
#6 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Action\/Plugin\/Design.php(48): Magento\\Framework\\View\\DesignLoader->load()\n
#7 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(121): Magento\\Framework\\App\\Action\\Plugin\\Design->beforeDispatch(Object(Magento\\Cms\\Controller\\Index\\Index\\Interceptor), Object(Magento\\Framework\\App\\Request\\Http))\n
#8 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(153): Magento\\Cms\\Controller\\Index\\Index\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n
#9 \/var\/www\/vhosts\/demo.com\/eiselec\/generated\/code\/Magento\/Cms\/Controller\/Index\/Index\/Interceptor.php(39): Magento\\Cms\\Controller\\Index\\Index\\Interceptor->___callPlugins('dispatch', Array, Array)\n
#10 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/FrontController.php(55): Magento\\Cms\\Controller\\Index\\Index\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n
#11 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(58): Magento\\Framework\\App\\FrontController->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n
#12 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(138): Magento\\Framework\\App\\FrontController\\Interceptor->___callParent('dispatch', Array)\n
#13 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/module-store\/App\/FrontController\/Plugin\/RequestPreprocessor.php(94): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n
#14 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(135): Magento\\Store\\App\\FrontController\\Plugin\\RequestPreprocessor->aroundDispatch(Object(Magento\\Framework\\App\\FrontController\\Interceptor), Object(Closure), Object(Magento\\Framework\\App\\Request\\Http))\n
#15 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/module-page-cache\/Model\/App\/FrontController\/BuiltinPlugin.php(73): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n
#16 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(135): Magento\\PageCache\\Model\\App\\FrontController\\BuiltinPlugin->aroundDispatch(Object(Magento\\Framework\\App\\FrontController\\Interceptor), Object(Closure), Object(Magento\\Framework\\App\\Request\\Http))\n
#17 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/Interception\/Interceptor.php(153): Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n
#18 \/var\/www\/vhosts\/demo.com\/eiselec\/generated\/code\/Magento\/Framework\/App\/FrontController\/Interceptor.php(26): Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins('dispatch', Array, NULL)\n
#19 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Http.php(135): Magento\\Framework\\App\\FrontController\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n
#20 \/var\/www\/vhosts\/demo.com\/eiselec\/vendor\/magento\/framework\/App\/Bootstrap.php(256): Magento\\Framework\\App\\Http->launch()\n
#21 \/var\/www\/vhosts\/demo.com\/eiselec\/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n
#22 {main}","url":"\/","script_name":"\/index.php"}

Hãy cho tôi biết làm thế nào tôi có thể giải quyết nó.

Cảm ơn


Xin chào, tôi đang nói về giá trị tuần tự hóa không giá trị uneriaize.
Meetanshi

Bạn đã thử xóa bộ nhớ cache? Không chỉ bộ nhớ cache Magento, bộ nhớ cache bên ngoài quá nếu có.
MGento

vâng, tôi đã thử
Meetanshi

Bạn có thể thử tìm hiểu xem, dữ liệu nào bạn đang cố gắng nối tiếp? Hãy thử duyệt qua các mô-đun bên thứ ba của bạn và tìm hiểu, từ mô-đun này, lỗi này được kích hoạt. Bạn có thể cần ghi đè chức năng tuần tự hóa, trong tệp /vendor/magento/framework/Serialize/Serializer/Json.php
MGento

Là lỗi này xảy ra trong quá trình cập nhật DB hoặc sau khi bạn cập nhật DB lên 2.2.1?
vẽ7721

Câu trả lời:


4

tôi có hành vi tương tự với một mẫu. Tôi đã sao chép mã lỗi vào serializer của mình để gặp vấn đề.

Ngay sau khi tôi chuyển sang de_DE và tạo lại mã tĩnh của mình thông qua

sudo php bin/magento setup:static-content:deploy de_DE --jobs=0 -f

nó ném "các ký tự UTF-8 không đúng định dạng, có thể được mã hóa sai".

Vì vậy, tôi đã tra cứu các tệp tôi đã thay đổi trong thư mục mẫu (ví dụ: mã / Mytheme / Bannerslider / i18n / de_DE.csv) và tải chúng qua WinSCP. Notepad ++ đã hiển thị "Ansii Encoding" - tôi đã sử dụng "magento i18n: coll-cụm từ" cho tệp dịch để tạo.

magento2dev # encguess app/code/MyTheme/Bannerslider/i18n/de_DE.csv

ứng dụng / mã / MyTheme / Bannerslider / i18n / de_DE.csv US-ASCII

magento2dev # locale
LANG=de_DE.UTF-8
......

Vì vậy, tôi đã thay đổi các tệp theo cách thủ công trong Notepad ++, tải chúng lên, triển khai nội dung tĩnh và đặt lại tất cả các quyền - vi voila nó hoạt động.

Vì vậy, lỗi có thể nằm trong tệp csv i18n của bạn.


10

Như tôi có thể thấy lỗi này xuất phát từ phương thức:

/**
 * Saving data cache
 *
 * @return $this
 */
protected function _saveCache()
{
    $this->_cache->save($this->getSerializer()->serialize($this->getData()), $this->getCacheId(true), [], false);
    return $this;
}

và serializer không tìm thấy xuất phát từ phương thức:

/**
 * Get serializer
 *
 * @return \Magento\Framework\Serialize\SerializerInterface
 * @deprecated 100.2.0
 */
private function getSerializer()
{
    if ($this->serializer === null) {
        $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
            ->get(Serialize\SerializerInterface::class);
    }
    return $this->serializer;
}

Tùy chọn cho SerializerInterfaceđã được thêm từ phiên bản 2.2.x của Magento và được khai báo trong ứng dụng / etc / di.xml :

<preference for="Magento\Framework\Serialize\SerializerInterface" type="Magento\Framework\Serialize\Serializer\Json" />

Vì vậy, tôi nghĩ rằng bộ nhớ cache của bạn đã cũ hoặc tùy chọn SerializerInterfacekhông hoạt động. Cố gắng gỡ lỗi vấn đề này bằng cách gọi Magento\Framework\Serialize\SerializerInterface(sử dụng nội xạ phụ thuộc) ở đâu đó trong mã và kiểm tra lớp nào được trả về bởi di:

public function __construct(\Magento\Framework\Serialize\SerializerInterface $serializer) 
{ 
    echo get_class($serializer);
}

Nếu nó trả về không phải là một thể hiện của Magento\Framework\Serialize\Serializer\Jsonlớp được trả về - hãy thử tìm kiếm tùy chọn ghi đè này trong dự án và loại bỏ nó.

Nếu bạn đang làm việc trên máy chủ từ xa - trước tiên hãy kiểm tra app/etc/di.xmltệp trực tiếp trên máy chủ.

Một cách khác để bạn có thể sửa đổi tạm thời bộ Jsontuần tự lõi và kiểm tra lỗi nào được trả về:

Mở magento/framework/Serialize/Serializer/Json.phpvà thay đổi phương thức này từ:

/**
 * {@inheritDoc}
 * @since 100.2.0
 */
public function serialize($data)
{
    $result = json_encode($data);
    if (false === $result) {
        throw new \InvalidArgumentException('Unable to serialize value.');
    }
    return $result;
}

đến:

/**
 * {@inheritDoc}
 * @since 100.2.0
 */
public function serialize($data)
{
    $result = json_encode($data);
    if (false === $result) {
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                $error = ' - No errors';
                break;
            case JSON_ERROR_DEPTH:
                $error = ' - Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $error = ' - Underflow or the modes mismatch';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $error = ' - Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                $error = ' - Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                $error = ' - Malformed UTF-8 characters, possibly incorrectly encoded';
                break;
            default:
                $error = ' - Unknown error';
                break;
        }
        throw new \InvalidArgumentException('Unable to serialize value. Error: ' . $error);
    }

    return $result;
}

Sau đó, bạn có thể thấy sau thông báo ngoại lệ một lỗi json. Có thể dữ liệu của bạn bị hỏng. Hãy nhớ rằng tất cả các dữ liệu cũ sẽ không được xác thực và tuần tự hóa bằng cách sử dụng json trong các kịch bản nâng cấp thiết lập trong quá trình cập nhật magento.

PS: đừng quên hoàn nguyên các tệp cốt lõi sau khi gỡ lỗi hoàn tất! Cách tốt hơn là sử dụng xDebug cho mục đích đó.


2
Bạn nên biến trình gỡ lỗi đó thành trình vá lỗi cốt lõi - hoặc đề nghị họ sử dụng SAFE PHP github.com/thecodingmachine/safe
Alex

1

Tôi đã gặp vấn đề tương tự với việc nâng cấp lên 2.2.1. Tôi thấy articel này rất hữu ích http://devdocs.magento.com/guides/v2.2/ext-best-practices/tutorials/serialized-to-json-data-upTHER.html

Dữ liệu được lưu trữ trong DB không nên được tuần tự hóa nữa, bây giờ nó sẽ được lưu dưới dạng đối tượng JSON.

Hầu hết các mô-đun thực hiện cập nhật dữ liệu không xác định dữ liệu trong DB và lưu trữ lại dưới định dạng JSON. (BTW Mất khá nhiều thời gian để chạy nó ...)

Do đó, nếu một trong các mô-đun của bạn lưu dữ liệu được tuần tự hóa trong DB mà Magento có thể không đọc được dữ liệu nữa, bạn sẽ cần tạo tệp Cài đặt nâng cấp dữ liệu. Ngoài ra, nó có thể là mô-đun của bên thứ 3 cần được cập nhật lên phiên bản tương thích 2.2+.

Nếu bạn thực hiện tuần tự hóa dữ liệu không xác định bất cứ nơi nào trong mã của bạn, bạn cũng có thể phải thay đổi điều đó.

Tôi hy vọng điều này cung cấp cho bạn cái nhìn sâu sắc hơn về những gì gây ra lỗi này.

Chúc mừng!


Đảm bảo đọc Ghi chú phát hành cho 2.2.1, rất nhiều thứ đã thay đổi, bao gồm cả đường dẫn cho generationthư mục. ;)
vẽ7721

1

Tôi đã kết thúc chính xác đến tình huống tương tự. Sau khi thêm mã ở trên, tôi nhận được "Các ký tự UTF-8 không đúng định dạng, có thể được mã hóa không chính xác"

Tôi cho rằng bạn không sử dụng ngôn ngữ mặc định. Cố gắng thay đổi ngôn ngữ thành "mặc định" en_US.

Meetanshi - Ngôn ngữ nào bạn đang sử dụng ở mặt trước và việc tạo nội dung tĩnh cũng thất bại?


Xin chào @AP, tôi đang gặp phải lỗi tương tự và tôi đang sử dụng ngôn ngữ de_DE.
Meetanshi

Hãy thử thay đổi thành en_US. Bảng core_config_data (chung / ngôn ngữ / mã) thành en_US
AP

lỗi tương tự sau khi thay đổi thành en_US.
Meetanshi

Tôi đã xoay sở để có được nó, nhưng đã hết thời gian khi cố gắng quay trở lại fi_FI. Bạn đã xóa bộ nhớ cache?
AP

vâng, tôi đã xóa bộ nhớ cache
Meetanshi

1

Trong trường hợp của tôi, nguyên nhân của vấn đề Mã hóa UTF8, là việc rút ngắn tên sản phẩm không an toàn đa bào:

$productName = strlen($productName) > 60 ? substr($productName,0,60)."..." : 
      $productName;

Vậy một

012345678901234567890123456789012345678901234567890123456 Außengewinde 

đã trở thành

012345678901234567890123456789012345678901234567890123456 Au�...

Đây cũng là vấn đề của chúng tôi. ixed nó bằng cách thay thế "chất nền" bằng "mb_substr"
amesh

1

Hãy cẩn thận với chức năng cơ chất. Nó không hỗ trợ UTF-8. Và điều này có thể phá vỡ FPC. Sử dụng mb_substr


0

Đối với tôi, giải pháp là thay thế tất cả các ký tự đặc biệt như "ä" trong tệp dịch csv bằng các phiên bản html của cùng một ký tự như thế này:

&auml;

Sau đó, tôi xóa bộ nhớ cache và tải lại frontend.

Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.