I get a warrning on Magento\Catalog\Block\Product\ListProduct->getIdentities()

Warning: Invalid argument supplied for foreach() 

I checked the specified method but I do not understand what does return

     * Return identifiers for produced content
     * @return array
    public function getIdentities()
        $identities = [];
        foreach ($this->_getProductCollection() as $item) {
            $identities = array_merge($identities, $item->getIdentities());
        $category = $this->getLayer()->getCurrentCategory();
        if ($category) {
            $identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
        return $identities;

locally I set var_dump() and die but is never getting touched

  • great thanks! now I know that is used for caching but still not know why this warning breaks the page
    – deroccha
    May 4, 2016 at 11:09
  • probably because $this->_getProductCollection() is empty or not an array May 4, 2016 at 11:10
  • So on development I do not have page cache enabled the error is not present, in a custom module I override the _getProductCollection() method to check for child products if there ar no child product I return null, so how would I suppress this error?
    – deroccha
    May 4, 2016 at 11:19
  • 1
    Instead of returning null, return an empty array May 4, 2016 at 11:19
  • I posted the solution as answer so you can close the question May 4, 2016 at 11:24

1 Answer 1


Your problem is most likely due to the fact that your custom module overriding _getProductCollection() method returns null.

If you return an empty array instead it should fix your problem.

Not the answer you're looking for? Browse other questions tagged or ask your own question.