paynl / magento2-plugin

The Pay. plugin for Magento 2
https://www.pay.nl
27 stars 31 forks source link

Invalid argument supplied for foreach() in Model/Config/Source/PinTerminals.php on line 86 #168

Closed iwanvanzijderveld closed 2 years ago

iwanvanzijderveld commented 2 years ago

When I upgrade from version 2.4.0 to 2.5.1 I receive an error on the admin payment methods page.

The exception:

1 exception(s):
Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /var/www/html/vendor/paynl/magento2-plugin/Model/Config/Source/PinTerminals.php on line 86

These lines of code appear to be the issue.

$terminals = \Paynl\Instore::getAllTerminals();
$terminals = $terminals->getList();
foreach ($terminals as $terminal) {
         $terminal['visibleName'] = $terminal['name'];
         array_push($terminalArr, $terminal);
}
$cache->save(json_encode($terminalArr), $cacheName);

When I dump $terminals = \Paynl\Instore::getAllTerminals(); I get. object(Paynl\Result\Instore\Terminals)#3312 (1) { ["data":protected]=> array(2) { ["request"]=> array(3) { ["result"]=> string(1) "1" ["errorId"]=> string(0) "" ["errorMessage"]=> string(0) "" } ["terminals"]=> string(0) "" } }

When I dump $terminals = $terminals->getList(); I get an empty string.

I think that either the ->getList() function should return an empty array in this case or there should be a check that $terminals is iterable.

woutse commented 2 years ago

Thanks for your message. We'll look into it asap!

woutse commented 2 years ago

This is fixed in release 2.6.0!