Hi all,
we've set up our store with Magento 2.02 recently. We tried all available extensions for dependent custom options available for Magento 2. With every extensions we get the following error you can see below. This error occurs after 200 to 250 custom options.
a:4:{i:0;s:148:"Warning: Invalid argument supplied for foreach() in /var/www/magento/vendor/magento/module-catalog/Block/Product/ProductList/Related.php on line 129";i:1;s:3751:"#0 /var/www/magento/vendor/magento/module-catalog/Block/Product/ProductList/Related.php(129): Magento\Framework\App\ErrorHandler->handler(2, 'Invalid argumen...', '/var/www/magent...', 129, Array)
#1 /var/www/magento/vendor/magento/module-page-cache/Model/Layout/LayoutPlugin.php(71): Magento\Catalog\Block\Product\ProductList\Related->getIdentities()
#2 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(150): Magento\PageCache\Model\Layout\LayoutPlugin->afterGetOutput(Object(Magento\Framework\View\Layout\Interceptor), '<link rel="styl...')
#3 /var/www/magento/var/generation/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#4 /var/www/magento/vendor/magento/framework/View/Result/Page.php(241): Magento\Framework\View\Layout\Interceptor->getOutput()
#5 /var/www/magento/vendor/magento/framework/View/Result/Layout.php(162): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#6 [internal function]: Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#7 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#8 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#9 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-varnish-...')
#10 /var/www/magento/vendor/magento/module-page-cache/Model/Controller/Result/VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#11 [internal function]: Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#12 /var/www/magento/vendor/magento/framework/Interception/Chain/Chain.php(68): call_user_func_array(Array, Array)
#13 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(136): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-builtin-...')
#14 /var/www/magento/vendor/magento/module-page-cache/Model/Controller/Result/BuiltinPlugin.php(67): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#15 [internal function]: Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#16 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(141): call_user_func_array(Array, Array)
#17 /var/www/magento/var/generation/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#18 /var/www/magento/vendor/magento/framework/App/Http.php(119): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#19 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#20 /var/www/magento/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#21 {main}";s:3:"url";s:28:"/index.php/unterschrank.html";s:11:"script_name";s:10:"/index.php";}
Most likely this is a Magento issue not an extension issue.
Regards and a huge thanks Jule
@jusemjo Do you run into the issue without these extensions installed? I would suggest reporting this to the module vendors. Their module names aren't referenced in the backtrace, but my guess is if this only occurs when their module is installed, it has something to do with the manipulations they are making to products, causing an issue in the related products processing later on down the line.
@davidalger Thanks for your answer.
Actually I can not really verify if this error occurs without the extension installed because I can not set up any dependent custom options without an extension.
If I disable the extension the product gets shown regularly. But it also gets shown regularly if use less than 200 dependent custom options - that's why we assume it has something to do with Magento as well. Above 200 we receive the attached system error.
We've already contacted their support (at the moment Itoris - Dynamic Product Options for Magento 2 and hottons - dependent custom options are available)
@jusemjo Ok. Since this is an issue related to using a 3rd-party module, I'm going to go ahead and mark this as closed. However, if you run into this exception (or similar) loading up a product page without this extension in the mix, let us know, preferably along with steps to reproduce and I will be glad to re-open it!
When you feed a foreach with data that are not an array, you get a warning:
Warning: Invalid argument supplied for foreach() in...
rewrite the function like this to handle the null values:
public function getIdentities()
{
$identities = [];
if (is_array($this->getItems()) || is_object($this->getItems()))
{
foreach ($this->getItems() as $item)
{
$identities = array_merge($identities, $item->getIdentities());
}
}
return $identities;
}
@jusemjo: you ever figured out what causes this, because I believe it's a core Magento bug:
https://github.com/magento/magento2/issues/5897
@hostep Has this been resolved? Why did you close #5897?
And as far as I know it hasn't been resolved yet.
@surfer190: please look at the green 'open' label at the top in the left corner, the red 'closed' label at the bottom right is associated with this ticket ;)
Most helpful comment
When you feed a foreach with data that are not an array, you get a warning:
rewrite the function like this to handle the null values: