Magento 2.3 product collection->getData get correct answer but foreach or load() not

by Kai Kang   Last Updated June 29, 2020 23:09 PM

enter image description hereSame with here : Magento 1: $productCollection->getData() vs foreach ($productCollection as $product), want add more information. Create new product then

$productCollection = $objectManager->get('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create()->setStoreId('0')
->addAttributeToFilter('entity_id', '1638763');


var_dump($productCollection->getData());  // return the item
foreach ($productCollection as $key => $item) {
}. // nothing in here 

And try


Both method return null, Why I can't get the item after load() or using foreach function?

Related Questions

Filter products by website using AND

Updated July 14, 2015 13:04 PM

Magento 2, filtering product collection and sorting

Updated March 07, 2018 08:09 AM