Is there a way to modify the value of the Quote item/Product item before being saved in the Quote Item table? Let say I added a product in the cart, I can see that this product is added in the Quote Item Table in the DB. Now what I want is update that value first before saving it in the DB. So basically I want to make the value of the item is_virtual set to 1. The original Product is set to is_virtual = 0 but what I want is when I add this product to cart I want to update the value in the Quote_item table for column is_virtual and set it to 1. How can I achieve this? I think it can be done via plugin or observer? Like before_set_product or something. Is this possible and available? How do I do this?
Update: Just for reference I followed this same idea
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="checkout_cart_product_add_after"> <observer name="set_is_virtual" instance="Vendor\Checkout\Observer\UpdateIsVirtual" /> </event> </config> And the observer is like this
<?php namespace Vendor\Checkout\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\RequestInterface; class UpdateIsVirtual implements ObserverInterface { public function execute(\Magento\Framework\Event\Observer $observer) { $item = $observer->getEvent()->getData('quote_item'); $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); $item->setIsVirtual(1); } } This doesn't update the entry in the Quote Item table. I want the entry in the Quote Item table to be updated as well as it's the most important thing I need to accomplish