Invalid argument supplied for foreach() in /var/www/html/app/code/Ves/Megamenu/Model/Config/Source/StoreCategories.php on line 284

magento.stackexchange https://magento.stackexchange.com/questions/277672

  •  03-03-2021
  •  | 
  •  

Question

I have this error when I add special characters to menu or categories like "&" It's from module Ves Megamenu.

Warning: Invalid argument supplied for foreach() in /var/www/html/app/code/Ves/Megamenu/Model/Config/Source/StoreCategories.php on line 284

Warning Line:

$categoriesTrees = $this->getCategoriesTree();
foreach ($categoriesTrees as $category) {
    $this->generatCategory($category);
}
Was it helpful?

Solution

Solutions was to change this line to:

$categoriesTrees = $this->getCategoriesTree();
if(is_array($categoriesTrees)){
   foreach ($categoriesTrees as $category) {
       $this->generatCategory($category);
   }
}

Now I can use "&" or "/" in categories names, without crashing the site.

Useful source: https://thisinterestsme.com/invalid-argument-supplied-for-foreach/

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top