2

I am getting this error on some Products on Magento 2.3 when I try to view them:

1 exception(s): Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/Block/Product/View/Options.php on line 215

Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/Block/Product/View/Options.php on line 215
#0 /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/Block/Product/View/Options.php(215): Magento\Framework\App\ErrorHandler->handler(2, 'Invalid argumen...', '/www/htdocs/w01...', 215, Array)
#1 /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/view/frontend/templates/product/view/options.phtml(19): Magento\Catalog\Block\Product\View\Options->getJsonConfig()
#2 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/www/htdocs/w01...')
#3 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Options), '/www/htdocs/w01...', Array)
#4 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(301): Magento\Framework\View\Element\Template->fetchView('/www/htdocs/w01...')
#5 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#6 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Element\AbstractBlock->toHtml()
#7 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('product.info.op...')
#8 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.info.op...')
#9 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.info.op...')
#10 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.info.op...', true)
#11 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/AbstractBlock.php(512): Magento\Framework\View\Layout\Interceptor->renderElement('product.info.op...', true)
#12 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(778): Magento\Framework\View\Element\AbstractBlock->getChildHtml('', true)
#13 /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/view/frontend/templates/product/view/options/wrapper.phtml(15): Magento\Catalog\Block\Product\View\Interceptor->getChildHtml('', true)
#14 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/www/htdocs/w01...')
#15 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Interceptor), '/www/htdocs/w01...', Array)
#16 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(544): Magento\Framework\View\Element\Template->fetchView('/www/htdocs/w01...')
#17 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(301): Magento\Catalog\Block\Product\View\Interceptor->fetchView('/www/htdocs/w01...')
#18 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#19 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(869): Magento\Framework\View\Element\AbstractBlock->toHtml()
#20 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(557): Magento\Catalog\Block\Product\View\Interceptor->toHtml()
#21 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('product.info.op...')
#22 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.info.op...')
#23 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.info.op...')
#24 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.info.op...', true)
#25 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/AbstractBlock.php(543): Magento\Framework\View\Layout\Interceptor->renderElement('product.info.op...', true)
#26 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(791): Magento\Framework\View\Element\AbstractBlock->getChildChildHtml('options_contain...', '', true)
#27 /www/htdocs/w018f7f2/pema/vendor/magento/module-catalog/view/frontend/templates/product/view/form.phtml(37): Magento\Catalog\Block\Product\View\Interceptor->getChildChildHtml('options_contain...')
#28 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/www/htdocs/w01...')
#29 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Interceptor), '/www/htdocs/w01...', Array)
#30 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(544): Magento\Framework\View\Element\Template->fetchView('/www/htdocs/w01...')
#31 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/Template.php(301): Magento\Catalog\Block\Product\View\Interceptor->fetchView('/www/htdocs/w01...')
#32 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Element/AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#33 /www/htdocs/w018f7f2/pema/generated/code/Magento/Catalog/Block/Product/View/Interceptor.php(869): Magento\Framework\View\Element\AbstractBlock->toHtml()
#34 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(557): Magento\Catalog\Block\Product\View\Interceptor->toHtml()
#35 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('product.info')
#36 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.info')
#37 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.info')
#38 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.info', false)
#39 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('product.info', false)
#40 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('product.info.ma...', false)
#41 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('product.info.ma...')
#42 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('product.info.ma...')
#43 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('product.info.ma...', false)
#44 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('product.info.ma...', false)
#45 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('content', false)
#46 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('content')
#47 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('content')
#48 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('content', false)
#49 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('content', false)
#50 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('main', false)
#51 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main')
#52 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main')
#53 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main', false)
#54 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('main', false)
#55 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('columns', false)
#56 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#57 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('columns')
#58 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('columns', false)
#59 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('columns', false)
#60 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('main.content', false)
#61 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#62 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main.content')
#63 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main.content', false)
#64 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('main.content', false)
#65 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#66 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#67 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper')
#68 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#69 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper', false)
#70 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('root', false)
#71 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('root')
#72 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root')
#73 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('root', true)
#74 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Layout.php(954): Magento\Framework\View\Layout\Interceptor->renderElement('root')
#75 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#76 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#77 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#78 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#79 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Result/Page.php(258): Magento\Framework\View\Layout\Interceptor->getOutput()
#80 /www/htdocs/w018f7f2/pema/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#81 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#82 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#83 /www/htdocs/w018f7f2/pema/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#84 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#85 /www/htdocs/w018f7f2/pema/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#86 /www/htdocs/w018f7f2/pema/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()
#87 /www/htdocs/w018f7f2/pema/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http\Interceptor->launch()
#88 /www/htdocs/w018f7f2/pema/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#89 {main}

Any Ideas?

  • kindly mention your Magento version and PHP version – ARUNPRABAKARAN M Apr 11 at 7:12
  • Magento 2.3 PHP v. 7.2 – Ken Apr 11 at 7:47
0

Invalid argument supplied for foreach() is the warning occurs when you pass null to foreach() instead of array.

if it is related to product then may be your product collection return an instance instead of array. So use this

return $collection->getData();

instead of

return $collection;

in your getProductCollection() function

I hope this will help

  • It is related to a few Products. Not all. How do i use return $collection->getData(); Not very familiar with magento. – Ken Apr 11 at 7:49
  • Yes because not every time you got null in your collection instance that's why it occurs in few products – Muhammad Hasham Apr 11 at 7:53
  • Okay, where do i find that function? I have tried in list.phtml but can not find return $collection; – Ken Apr 11 at 8:06
  • You can find the getProductCollection() function in your module block. if my answer is helpful please mark my answer correct and upvote my answer. so it helps other readers as well – Muhammad Hasham Apr 11 at 8:11
  • Sorry but i can not find the file where i have to change the function. can you give me the filename and path so i can try? I am new to magento. – Ken Apr 11 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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