Magento 2 – Get Quote Item Collection by Quote Item ID

collection;magento2modelquotequoteitem

I get the quote_item_id like this:

$orderItems = $order->getAllItems();
foreach($orderItems as $orderItem){
    $qouteItemId = $orderItem->getQuoteItemId();
}

I need to load quote item collection using quote_item_id.

Is there a way to do it?

Best Answer

private $quoteItemFactory;
private $itemResourceModel;
public function __construct(
  .....
  \Magento\Quote\Model\Quote\ItemFactory $quoteItemFactory,
  \Magento\Quote\Model\ResourceModel\Quote\Item $itemResourceModel
  ......
) {
   ....
   $this->quoteItemFactory = $quoteItemFactory;
   $this->itemResourceModel = $itemResourceModel
   ...
}

and in one of the methods you can do this:

$itemId = your id here
$quoteItem = $this->quoteItemFactory->create();
$this->itemResourceModel->load($quoteItem, $itemId);