Hi there,
I'm getting this error when clicking on any product or category on my website.
1 exception(s): Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /home/thegift/public_html/app/code/Mageplaza/Search/Helper/Data.php on line 345 Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /home/thegift/public_html/app/code/Mageplaza/Search/Helper/Data.php on line 345 #0 /home/thegift/public_html/app/code/Mageplaza/Search/Helper/Data.php(345): Magento\Framework\App\ErrorHandler->handler(2, 'Invalid argumen...', '/home/thegift/p...', 345, Array) #1 /home/thegift/public_html/app/code/Mageplaza/Search/Helper/Data.php(322): Mageplaza\Search\Helper\Data->getCategoryOptions(Object(Magento\Catalog\Model\Category\Interceptor), Array, 1) #2 /home/thegift/public_html/app/code/Mageplaza/Search/view/frontend/templates/search.phtml(35): Mageplaza\Search\Helper\Data->getCategoryTree() #3 /home/thegift/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/thegift/p...') #4 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Framework\View\Element\Template), '/home/thegift/p...', Array) #5 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/thegift/p...') #6 /home/thegift/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #7 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml() #8 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('mageplaza.top.s...') #9 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('mageplaza.top.s...') #10 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('mageplaza.top.s...') #11 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('mageplaza.top.s...', true) #12 /home/thegift/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(511): Magento\Framework\View\Layout\Interceptor->renderElement('mageplaza.top.s...', true) #13 /home/thegift/public_html/app/design/frontend/Smartwave/porto/Magento_Search/templates/form.mini.phtml(40): Magento\Framework\View\Element\AbstractBlock->getChildHtml() #14 /home/thegift/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/thegift/p...') #15 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Framework\View\Element\Template), '/home/thegift/p...', Array) #16 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/thegift/p...') #17 /home/thegift/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #18 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml() #19 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('top.search') #20 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('top.search') #21 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('top.search') #22 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('top.search', true) #23 /home/thegift/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(507): Magento\Framework\View\Layout\Interceptor->renderElement('top.search', true) #24 [internal function]: Magento\Framework\View\Element\AbstractBlock->getChildHtml('top.search') #25 /home/thegift/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(82): call_user_func_array(Array, Array) #26 /home/thegift/public_html/app/design/frontend/Smartwave/porto/Smartwave_Porto/templates/html/header.phtml(179): Magento\Framework\View\TemplateEngine\Php->__call('getChildHtml', Array) #27 /home/thegift/public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/thegift/p...') #28 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Smartwave\Porto\Block\Template), '/home/thegift/p...', Array) #29 /home/thegift/public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/thegift/p...') #30 /home/thegift/public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml() #31 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml() #32 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('porto_header') #33 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('porto_header') #34 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('porto_header') #35 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('porto_header', false) #36 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(586): Magento\Framework\View\Layout\Interceptor->renderElement('porto_header', false) #37 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false) #38 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper') #39 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper') #40 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('page.wrapper', false) #41 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(586): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper', false) #42 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('root', false) #43 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('root') #44 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root') #45 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('root', true) #46 /home/thegift/public_html/vendor/magento/framework/View/Layout.php(955): Magento\Framework\View\Layout\Interceptor->renderElement('root') #47 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput() #48 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array) #49 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() #50 /home/thegift/public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array) #51 /home/thegift/public_html/vendor/magento/framework/View/Result/Page.php(257): Magento\Framework\View\Layout\Interceptor->getOutput() #52 /home/thegift/public_html/vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor)) #53 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor)) #54 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array) #55 /home/thegift/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor)) #56 /home/thegift/public_html/generated/code/Magento/Framework/View/Result/Page/Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array) #57 /home/thegift/public_html/vendor/magento/framework/App/Http.php(139): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor)) #58 /home/thegift/public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch() #59 /home/thegift/public_html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch() #60 /home/thegift/public_html/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor)) #61 {main}
I have checked line 345 in the Data.php file
foreach ($this->getChildCategories($category) as $childCategory) { $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix);
Any ideas on why this is happening
Magento 2.2.3 Theme Porto module-core up to date
I'm getting the same issue. Disabling Mageplaza search and clearing cache removed the problem for me but then i cant use the Extension. Re-enabling Mageplaza search just brings the problem back. I initially had an issue installing a theme as I already had the core installed as I was using SMTP by Mageplaza. The theme tried to install Mageplaza core initially but it was already present so Install failed. Removing Mageplaza core folders in app and vendor then tidying composer meant i was able to install my new theme, but then this problem. For ref I will be raising the issue with Mageplaza.
Hello @andrew_woodward
As we can see at the line no. 345, There is a loop of the child categories.
Probably there are no child categories in the category which you are trying to open in your browser.
You have to add the if condition to check if this category has the child categories or not.
You can do as given below.
if ($this->getChildCategories($category)) { foreach ($this->getChildCategories($category) as $childCategory) { $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix); } }
thanks this is working fine in magento 2.2.5 .
@Mayur Bhuva wrote:Hello @andrew_woodward
As we can see at the line no. 345, There is a loop of the child categories.
Probably there are no child categories in the category which you are trying to open in your browser.
You have to add the if condition to check if this category has the child categories or not.
You can do as given below.
if ($this->getChildCategories($category)) { foreach ($this->getChildCategories($category) as $childCategory) { $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix); } }
thanks your code (trick) is working for me in magento 2.2.5
@vivek_aris wrote:thanks this is working fine in magento 2.2.5 .
@Mayur Bhuva wrote:Hello @andrew_woodward
As we can see at the line no. 345, There is a loop of the child categories.
Probably there are no child categories in the category which you are trying to open in your browser.
You have to add the if condition to check if this category has the child categories or not.
You can do as given below.
if ($this->getChildCategories($category)) { foreach ($this->getChildCategories($category) as $childCategory) { $this->getCategoryOptions($childCategory, $options, $level, $htmlPrefix); } }
thanks this is working fine in magento 3.2.1 too
worked like a charm cheers!
Yeah
I had a similar error for smtp and to resolve it I opted to switch to magepal smtp.
But for Mageplaza_search I still haven't found a replacement.