5

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?

  • do you need quote item Id? – MR.R DNATH Jul 4 '18 at 7:28
9
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);
|improve this answer|||||
  • I have try above code for load Quote Item by item id but i am getting following error. "Fatal Error: 'Uncaught Error: Call to undefined method Magento\\Quote\\Model\\ResourceModel\\Quote\\Item::getProductId() – Niranjan Gondaliya Oct 22 '18 at 11:06
0

you can inject in your class an instance of \Magento\Quote\Model\QuoteFactory.

protected $quoteFactory;

public function __construct(
    ...
    \Magento\Quote\Model\QuoteFactory $quoteFactory,
    ....
) {
    ....
    $this->quoteFactory = $quoteFactory;
    ....
}

Then you can use:

$quote = $this->quoteFactory->create()->load($quoteId);
|improve this answer|||||
  • i need to load quote item using quote item id not load quote by quote id – Tiny Dancer Jul 4 '18 at 7:30
0

you can load the quote id by injecting the instance of \Magento\Quote\Model\QuoteFactory

protected $quoteFactory;
public function __construct(
  .....
  \Magento\Quote\Model\QuoteFactory $quoteFactory
  ......
){
   $this -> quoteFactory = $quoteFactory;
}

$quote = $this->quoteFactory->create()->load($quoteId);
$items = $quote->getAllItems();
|improve this answer|||||
  • i need to load quote item using quote item id not load quote by quote id – Tiny Dancer Jul 4 '18 at 7:30
  • Yes you can get items by $items = $quote->getAllItems(); – Suresh Chikani Jul 4 '18 at 7:32
0

First load the quote object

 $quote = $this->quoteRepository->getActive($cartId);
  foreach ($quote->getItems() as $item) {    
         $quoteItem = $quote->getItemById($item->getItemId()); 
  }
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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