I am trying to update quote item in magento2. But every time i am saving the item its creating a new item with the same quote id rather than updating it. Here is my code
public function __construct(
\Magento\Quote\Model\QuoteRepository $quoteRepo
){
$this->_quoteRepo = $quoteRepo;
}
public function updateItem(){
$quote = $this->_quoteRepo->get('id here');
foreach($quote->getAllVisibleItems() as $itemq){
$itemq->setQty(5);
$itemq->setPrice(20);
$itemq->save();
}
}
But every time its saving an item.. a new item is getting generated. Dont know why. Also I couldn't find any class which explicitly load qoute item in magento2
. Help will be appreciated.
In this question https://magento.stackexchange.com/questions/139298/how-to-save-quote-items-in-magento-2
they are setting the whole product... not trying to update it. When you set a product a new quote item will surely generate. But why its doing the same in case of updation.