0

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