Skip to main content
edited tags
Link
Fabian Schmengler
  • 66.1k
  • 25
  • 188
  • 422
Tweeted twitter.com/StackMagento/status/913639118508306432
Source Link
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