3

How can this be solved after upgrading magento 2.2.X to 2.3.X : enter image description here

  • Try refreshing Redis Cache. – Muzammal Hassan Aug 27 '19 at 7:09
  • yes i have done this but it didn't work even – Vikas kalal Aug 27 '19 at 7:10
  • After running which command you are getting this error – ASQ Aug 27 '19 at 7:12
  • after upgrading magento 2.2.X to 2.3.X and i have deployed all magento command. – Vikas kalal Aug 27 '19 at 7:14
  • try to run rm -rf pub/static/frontend and then check and let me know – ASQ Aug 27 '19 at 7:23
13

Go to this file location and paste below code and best way try to override this file : vendor/magento/framework/Serialize/Serializer/Json.php

public function utf8ize( $mixed ) {
    if (is_array($mixed)) foreach ($mixed as $key => $value) $mixed[$key] = $this->utf8ize($value);
    elseif (is_string($mixed)) return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
    return $mixed;
}

public function serialize($data){
    $result = json_encode( $this->utf8ize( $data ) );
    if (false === $result) {
        throw new \InvalidArgumentException("Unable to serialize value. Error: " . json_last_error_msg());
    }
    return $result;
}

How to override this file

The preference for the SerializerInterface was added since 2.2.x version of the Magento, and declared in the app/etc/di.xml:

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

Override Hint :

Then create the class [Vendor][Module]\Serialize\Serializer\Json that extends Magento\Framework\Serialize\Serializer\Json and make your changes in there.

  • This solved my issue also on Arabic site. – ishaq Dec 25 '20 at 11:15
0

Magento 2 checkout cart showing unable to unserialize value. Error syntax error for that error this solution may work.

Go to this path and replace method with below code. After applying this code please run below command

redis-cli flushall

vendor/magento/framework/Serialize/Serializer/Json.php

public function unserialize($string)
    {
        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            if(false !== @unserialize($string)){
                return unserialize($string);
            }
            throw new \InvalidArgumentException('Unable to unserialize value.');
        }
        return $result;
    }

And try to override this file using preference :

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

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.