I created a observer :
<?php
namespace VendorModuleObserver;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class SaveRefToQuote implements ObserverInterface
{
protected $logger;
protected $request;
/**
* Constructor
*
* @param LoggerInterface $logger
* @param RequestInterface $request
*/
public function __construct(LoggerInterface $logger, RequestInterface $request)
{
$this->logger = $logger;
$this->request = $request;
}
/**
* Execute observer
*
* @param Observer $observer
*/
public function execute(Observer $observer)
{
try {
$quote = $observer->getEvent()->getQuote();
// Use injected RequestInterface
$params = $this->request->getParams();
$this->logger->info('All request parameters: ' . json_encode($params));
$someField = $this->request->getParam('some_field');
$this->logger->info('Observer Triggered: ' . ($someField ?? 'No some_field'));
if ($someField) {
$quote->setData('some_field', $someField);
$this->logger->info('some_field saved to quote: ' . $someField);
}
} catch (Exception $e) {
$this->logger->error('Error in SaveRefToQuote Observer: ' . $e->getMessage());
}
}
}
And this is reponse from the json:
{"form":"sku","form_key":"8js7OyW7mshKq7vk","defaultMinQty":"1","defaultMaxQty":"10000","product-type":"","parent-class-id":"","item-id":"","items":[{"sku":"xyz","qty":"1","some_field":"zazazazaza"}]} [] []
Actually I want save the value of the some_field in the magento order for just record.
When I get the quote it is null.
Give me any solution that just save this field in the sales order for record as the field is getting in the json.
This is the etc/events.xml
<event name="sales_model_service_quote_submit_before">
<observer name="vendor_orderbysku_save_ref_to_quote" instance="VendorModuleObserverSaveRefToQuote" />
</event>
I also tried some other observers also.