I have to get the data from quote_item table using quote id and product id filter in Magento 2.

I was doing like this but it's not the good way

        ['ce' => 'quote_item'],
    )->where('ce.quote_id IN (?) ',$quoteId)
    ->where('ce.product_id IN (?) ',$product_id);
  • We need to think about the simple way in this case. Each quote item has a unique product id. So, in this case, we just need to load the quote item by quote id. And, need to get the product id for comparison. \Magento\Sales\Api\OrderItemRepositoryInterface -> get($id); \Magento\Sales\Api\Data\OrderItemInterface -> getProductId(); May 25 '18 at 6:36
  • @Amrit Pal Singh why not use \Magento\Quote\Model\Quote\ItemFactory to filter?
    – Sathish
    May 25 '18 at 7:22
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory as   QuoteFactory;

public function __construct(
    QuoteFactory $quoteFactory
) {
    $this->quoteFactory = $quoteFactory;

  • You can also get quote data by Magento\Quote\Model\QuoteRepository::get(quote_id)
    – HaFiz Umer
    Apr 25 '19 at 7:37

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.