1

I have create gift card product types and add custom options like this

  1. Choose Amount:Card value
  2. select a design:
  3. compose your email :

       To :
    
         Recipient Name
         Recipient Email
    
       Form :
    
         Sender Name
         Sender Email
    
  4. Headline:
  5. Message:
  6. Date to send:
  7. Time Zone

I added product into add to cart But, product is not update mini cart and checkout/cart page display error like this :

Exception #0 (InvalidArgumentException): Unable to unserialize value. #0 vendor/magento/module-catalog/Helper/Product/Configuration.php(118): Magento\Framework \Serialize\Serializer\Json->unserialize.

How to solve this type issue?

I tried the answers from "Magento 2.2 error: Unable to unserialize value" but this is not working.


enter image description here

3
  • i have already used this link but not working @Siarhey Uchukhlebau Dec 6, 2017 at 10:10
  • Try to debug from where this error comes (in backend). Check is taht error are reproducing when all third-party modules are disabled. Dec 6, 2017 at 10:14
  • now i am use magento 2.2.0 fresh version. @Siarhey Uchukhlebau Dec 6, 2017 at 11:05

1 Answer 1

2

Now i have got the solution.

app/code/Vendor/Module/Helper/Data.php

    public function getUnserializeData($data)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $version = $objectManager->get('Magento\Framework\App\ProductMetadataInterface')->getVersion();
        if($version >= '2.2.0'){
            $returnData = $objectManager->get('Magento\Framework\Serialize\SerializerInterface')->unserialize($data);
        }
        else{

            $returnData = (array) unserialize($data);
        }

        return $returnData;     
    }
    public function getSerializeData($data)
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $version = $objectManager->get('Magento\Framework\App\ProductMetadataInterface')->getVersion();
        if($version >= '2.2.0'){
            $returnData = $objectManager->get('Magento\Framework\Serialize\SerializerInterface')->serialize($data);
        }
        else{

            $returnData = serialize($data);
        }
        return $returnData;     
    }

app/code/Vendor/Module/Observer/CheckoutCartProductAddAfterObserver.php

        $additionalOptions = [];
        if ($additionalOption = $item->getOptionByCode('additional_options')) {

            $additionalOptions = $this->_helper->getUnserializeData($additionalOption->getValue());
        }


       if (count($additionalOptions) > 0) {
            $item->addOption([
                'code' => 'additional_options',
                'value' => $this->_helper->getSerializeData($additionalOptions)
            ]);
        }
2
  • 1
    my magento version is 2.2.5 but its not work. any other solution? Jul 13, 2018 at 10:39
  • It could be better with dependency injection. It is a good answer though. Upvote from my side :) Oct 18, 2018 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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