1

can any one help on how to fix this ??

Exception #0 (Exception): Notice: Undefined index: category-node-310 in /home/cp376418/public_html/app/code/TemplateMonster/Megamenu/Model/Configurator/Row/Column/Category.php on line 21

<?php namespace TemplateMonster\Megamenu\Model\Configurator\Row\Column;


class Category extends Entity
{
    public $rendererClass = 'Category';
    private $_subCategory;

    public function __construct(array $data = [])
    {
        parent::__construct($data);
    }

    public function getCategory()
    {
        if (!$this->_subCategory) {
            $nodes = $this->getNode()->getAllChildNodes();
            $this->_subCategory = $nodes['category-node-' . $this->getValue()];
        }
        return $this->_subCategory;
    }
}
4
  • Add code of this <i>/home/cp376418/public_html/app/code/TemplateMonster/Megamenu/Model/Configurator/Row/Column/Category.php</i> file in comment also Aug 3, 2018 at 0:08
  • <?php namespace TemplateMonster\Megamenu\Model\Configurator\Row\Column; class Category extends Entity { public $rendererClass = 'Category'; private $_subCategory; public function __construct( array $data = [] ) { parent::__construct($data); } public function getCategory() { if (!$this->_subCategory) { $nodes = $this->getNode()->getAllChildNodes(); $this->_subCategory = $nodes['category-node-' . $this->getValue()]; } return $this->_subCategory; } }
    – Greg
    Aug 3, 2018 at 4:43
  • Has someone got it running? After applying the above changes I got another error Fatal error: Uncaught Error: Call to a member function getChildren() on null in /var/www/clients/client210/web1638/web/app/code/TemplateMonster/Megamenu/view/frontend/templates/html/topmenu/block/row/column/category.phtml:3 Stack trace: #0 /var/www/clients/client210/web1638/web/vendor/magento/framework/View/TemplateEngine/Php.php(59): include() #1 /var/www/clients/client210/web1638/web/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(TemplateMonster\
    – Martin St
    Jan 22, 2019 at 16:41
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Jan 22, 2019 at 17:00

3 Answers 3

0

You have to modify at this code

$this->_subCategory = $nodes['category-node-' . $this->getValue()];

to

    if(isset($nodes['category-node-' . $this->getValue()])){
        $this->_subCategory = $nodes['category-node-' . $this->getValue()];
    }

Some value does not exits at $nodes arra that why it is creating issue.

2
  • so AMit just swap the top line of code out for the second?
    – Greg
    Aug 3, 2018 at 6:55
  • $nodes is an array.Category-node-310 index does not exist at this array.it is a PHP error
    – Amit Bera
    Aug 3, 2018 at 7:13
0

After some time our developer found a solution.

The reason is a bug in the big menue extension. If a category got deleted by accident it is still looking for the not existing child category.

Solution is to deactivated and than activate the parent category of the missing child category. Than it should work.

please find more detailed information how to reproduce and solve it in our blog https://www.konvis.de/neuigkeiten/magento/magento-2-magetique-template-big-menue-bug-and-solution-en/

0

This solution fixes it forever. Basically, if category doesnt exist, just don't show it.

app/code/TemplateMonster/Megamenu/view/frontend/templates/html/topmenu/block/row/column/category.phtml

<?php
$category = $this->getCategory();
if ($category) {
    $subCategories = $category->getChildren()->getIterator();
    //$showSubcategories = $this->getShowSubcategories($category);
    //$numberOfSubcategories = $this->getNumberOfSubcategories($category);
    $cssClass = $this->getCssClass($category);
    $image    = $this->getImage($category);

    ?>
    <ul class="mm-submenu level1">
        <li class="item<?php echo $cssClass; ?> ui-menu-item">
            <?php if ($image) : ?>
                <span class="mm-image"><img src="<?php echo $image; ?>" alt=""></span>
            <?php endif; ?>
            <a href="<?php echo $category->getUrl(); ?>">
                <?php if ($label = $category->getMmLabel()): ?>
                    <span class="mm-label"><?php echo $label; ?></span>
                <?php endif; ?>
                <?php echo $category->getName() ?>
            </a>
            <ul class="mm-submenu level2">
                <?php foreach ($subCategories as $subCategory): ?>
                    <?php $subCategoryCssClass = $this->getCssClass($subCategory); ?>
                    <?php $subSubCategories = $subCategory->getChildren()->getIterator(); ?>
                    <li class="item<?php echo (count($subSubCategories)) ? ' parent' : ''; ?><?php echo $subCategoryCssClass; ?> ui-menu-item">
                        <?php if ($label = $subCategory->getMmLabel()): ?>
                            <span class="mm-label"><?php echo $label; ?></span>
                        <?php endif; ?>
                        <?php if ($image = $this->getImage($subCategory)) : ?>
                            <span class="mm-image"><img src="<?php echo $image; ?>" alt=""></span>
                        <?php endif; ?>
                        <a href="<?php echo $subCategory->getUrl(); ?>"><?php echo $subCategory->getName(); ?></a>
                        <?php $showSubcategories = $this->getShowSubcategories($subCategory); ?>
                        <?php $numberOfSubcategories = $this->getNumberOfSubcategories($subCategory); ?>
                        <?php if ($subSubCategories && $showSubcategories): ?>
                            <ul class="mm-submenu level3 <?php echo $subCategory->getMmViewMode() ? 'vm-' . $subCategory->getMmViewMode() : 'vm-static'; ?>"
                                data-mage-init='{"subMenuViewMode": {}}'>
                                <?php for ($i = 0; $i < min(count($subSubCategories), $numberOfSubcategories); $i++): ?>
                                    <?php $curCategory = $subSubCategories->current(); ?>
                                    <?php $subCategoryCssClass = $this->getCssClass($curCategory); ?>
                                    <li class="item<?php echo $subCategoryCssClass; ?> ui-menu-item">
                                        <?php if ($label = $curCategory->getMmLabel()): ?>
                                            <span class="mm-label"><?php echo $label; ?></span>
                                        <?php endif; ?>
                                        <?php if ($image = $this->getImage($curCategory)) : ?>
                                            <span class="mm-image"><img src="<?php echo $image; ?>" alt=""></span>
                                        <?php endif; ?>
                                        <a href="<?php echo $curCategory->getUrl(); ?>"><?php echo $curCategory->getName(); ?></a>
                                    </li>
                                    <?php $subSubCategories->next(); ?>
                                <?php endfor; ?>
                                <?php if (count($subSubCategories) > $numberOfSubcategories): ?>
                                    <li class="show-all">
                                        <a href="<?php echo $subCategory->getUrl(); ?>"><?php echo __('Show all'); ?></a>
                                    </li>
                                <?php endif; ?>
                            </ul>
                        <?php endif; ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </li>
    </ul>

    <?php
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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