Skip to main content
1 of 2
simple guy
  • 2.5k
  • 8
  • 32
  • 59

Get item collection by sku Magento 2

I try to fetch quote item collection and add some filter like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$newItem = $objectManager->create('Magento\Quote\Model\ResourceModel\Quote\Item\Collection')
          ->addFieldToFilter('quote_id',$data['quote_id'])
          ->addFieldToFilter('store_id',$data['store_id'])
          ->addFieldToFilter('qty',$data['qty'])
          ->addFieldToFilter('sku',$data['sku'])->getFirstItem();
echo "<pre>";print_r($newItem->getData());exit;

but i got an error like this:

PHP Fatal error: Uncaught Error: Call to a member function getStoreId() on null in /var/www/magento/vendor/magento/module-quote/Model/ResourceModel/Quote/Item/Collection.php:98

simple guy
  • 2.5k
  • 8
  • 32
  • 59