Magento2 – Get quote_item Data Using Quote ID and Product ID Filter

magento2

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

$connection->select()
    ->from(
        ['ce' => 'quote_item'],
        ['length']
    )->where('ce.quote_id IN (?) ',$quoteId)
    ->where('ce.product_id IN (?) ',$product_id);

Best Answer

use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory as   QuoteFactory;

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

}
 $this->quoteFactory->create()->addFieldToFilter('quote_id',$quoteId)->addFieldToFilter('product_id',$productId);
Related Topic