<?php
namespace Namespace\Mymodule\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Serialize\SerializerInterface;
class SetAdditionalOptions implements ObserverInterface
{
/**
* @var RequestInterface
*/
protected $_request;
/**
* @param RequestInterface $request
*/
public function __construct(
RequestInterface $request,
SerializerInterface $serializer
) {
$this->_request = $request;
$this->serializer = $serializer;
}
/**
* @param \Magento\Framework\Event\Observer $observer
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
// Check and set information according to your need
if ($this->_request->getFullActionName() == 'checkout_cart_add') { //checking when product is adding to cart
$product = $observer->getProduct();
$additionalOptions = [];
$additionalOptions[] = array(
'label' => "Some'Some Label"Label',
'value' => "Your'Some Information"Info',
);
$observer->getProduct()->addCustomOption('additional_options', serialize$this->serializer->serialize($additionalOptions));
}
}
}
Need change in app/code/Namespace/Mymodule/Observer/SetAdditionalOptions.php