2

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
2
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);
  • 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);
  • 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();
  • 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

Following way you can load Quote Item by Item ID.

<?php

namespace Namespace\Module\Model;

class AddToWishlist
{
    /**
     * Quote repository.
     *
     * @var \Magento\Quote\Api\CartRepositoryInterface
    */

    protected $quoteRepository;

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

    /**
     * Returns Sucess message
     *
     * @api
     * @param string $customerId
     * @param string $cartId
     * @param string $itemId
     * @return array
    */

    public function addToWishlist($customerId, $cartId, $itemId)
    {
        $quote = $this->quoteRepository->getActive($cartId);
        $quoteItem = $quote->getItemById($itemId);
    }
}

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.