Magento2: Magento 2.3.3 to 2.3.4 Upgrade Issue: Invalid argument supplied for foreach() in /vendor/magento/module-catalog/Model/ProductLink/CollectionProvider.php on line 185

Created on 3 Mar 2020  路  7Comments  路  Source: magento/magento2

Hi Guys,
I've just upgraded my site from Magento 2.3.3 to 2.3.4. I'm using MGS Claue theme.
After the upgrade, I'm not able to edit the Products in the Admin.
It shows this error when I edit a product: Warning: Invalid argument supplied for foreach() in /vendor/magento/module-catalog/Model/ProductLink/CollectionProvider.php on line 185

issue

I've used composer for upgrade and followed the procedure from Magento Guide: https://devdocs.magento.com/guides/v2.3/comp-mgr/cli/cli-upgrade.html

Any help would be really appreciated.

ready for confirmation Reported on 2.3.3

Most helpful comment

I have the same error after i upgrade from Magento 2.3.3 to 2.3.4

All 7 comments

Hi @Jawwadiftikhar. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@Jawwadiftikhar do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

I have the same error after i upgrade from Magento 2.3.3 to 2.3.4

I got same error in the magento 2.3.5-p1

Screenshot_1

I found this variable $this->mapProviders is empty in /vendor/magento/module-catalog/Model/ProductLink/CollectionProvider.php file. This caused the problem. not sure what happened. I solved this problem by modifying the core magento file in /vendor/magento/module-catalog/Model/ProductLink/CollectionProvider.php. In getMap function, add this after if (!$types) {...}. So it'd be:

public function getMap(array $products, array $types): array
{
    if (!$types) {
        throw new \InvalidArgumentException('Types are required');
    }
   //FIX Warning: Invalid argument supplied for foreach() in /vendor/magento/module-catalog/Model/ProductLink/CollectionProvider.php on line 185
    if (!(is_array($this->mapProviders))) {
        $this->mapProviders = array(
            ObjectManager::getInstance()->create(LinkedMapProvider::class)
        );
    }
   ...

You need to import a few files as well on the top of this file:

use Magento\Catalog\Model\ProductLink\CollectionProvider\LinkedMapProvider;
use Magento\Framework\App\ObjectManager;

I know this fix is not clean as magento way. let me know if there is a better fix.

@magento-engcom-team any solution ?

I got same after upgrading to 2.4

Any solution, how to fix it

@advcha , please help us

Was this page helpful?
0 / 5 - 0 ratings