1

I want to update quote by quote id I have quote id . I have created the custom function on that function every time it's creating new quote row . I want to check if quote exists then update only else create.

0
1

You have to use CartRepository: \Magento\Quote\Api\CartRepositoryInterface.

Inject it via Constructor of your class

protected $quoteRepository;

public function __construct(
    ...
    \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
    ....
) {
    ....
    $this->quoteRepository = $quoteRepository;
    ....
}

and use in required method as:

$quote = $this->quoteRepository->get($quoteId);
$quote->setCustomerId($customerId); // Whatever you want to update
$this->quoteRepository->save($quote)

Refer - Magento 2: Understanding Object Repositories

2
  • Its overriding the data i want to update this will override the data for ex. that quote is having items_qty = 1 , if i will update then it should add the qty not override Oct 7 '16 at 10:55
  • @magento12345 why don't you read the current qty first, then sum it with new qty, and override it?
    – simple guy
    Jun 5 '17 at 1:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.