Update custom column data in quote table Magento 2
The easiest way to solve this is to fill in this field in the quote model and save it using the Repository:
class QuoteUpdater
{
/**
* @var \Magento\Quote\Model\QuoteRepository
*/
protected $quoteRepository;
/**
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
*/
public function __construct(
\Magento\Quote\Model\QuoteRepository $quoteRepository
) {
$this->quoteRepository = $quoteRepository;
}
public function updateQuoteData($quoteId, int $customData)
{
$quote = $this->quoteRepository->get($quoteId); // Get quote by id
$quote->setData('custom_column', $customData); // Fill data
$this->quoteRepository->save($quote); // Save quote
}
}
To set data in quote table, use below code -
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quoteId = 10;
$customColumnValue = 1;
$quote = $objectManager->create('Magento\Quote\Model\Quote')->load($quoteId);
$quote->setCustomColumn($customColumnValue);
$quote->save();
Here replace $quoteId variable with your quote ID .