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

asked Dec 6, 2017 at 9:41
3
  • i have already used this link but not working @Siarhey Uchukhlebau Commented 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. Commented Dec 6, 2017 at 10:14
  • now i am use magento 2.2.0 fresh version. @Siarhey Uchukhlebau Commented 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)
 ]);
 }
answered Jan 8, 2018 at 12:39
2
  • 1
    my magento version is 2.2.5 but its not work. any other solution? Commented Jul 13, 2018 at 10:39
  • It could be better with dependency injection. It is a good answer though. Upvote from my side :) Commented Oct 18, 2018 at 10:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.