2

A few days ago I was having this problem,( main.CRITICAL: Unable to unserialize value. {"exception":"[object] (InvalidArgumentException(code: 0): ) but I searched for this error, I found it, I replicated it this location public_html/vendor/magento/framework/Serialize/Serializer/Json.php

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

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

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

and I started getting this problem in orders.

enter image description here

Then I checked in the database and found out, when I mention this Null here, it works correctly.

Table: sales_order_item

enter image description here

i check this for get WeeeTax Applied

 public function getApplied($item)

{
    if ($item instanceof QuoteAbstractItem) {

        if ($item->getHasChildren() && $item->isChildrenCalculated()) 
 {
      $result = [];

       foreach ($item->getChildren() as $child) {

           $childData = $this->getApplied($child);

             if (is_array($childData)) {

                  $result = array_merge($result, $childData);
              }
          }
         return $result;
        }
    }

    $data = $item->getWeeeTaxApplied();

    if (empty($data)) {

return [];
    }
      return $this->serializer->unserialize($item- 
   >getWeeeTaxApplied());
 }

Plz can anyone help me

Thanks in advance

Your Answer

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

Browse other questions tagged or ask your own question.