How to resolve the Error “Call to a member function getChildren() on null” The 2019 Stack...

Is flight data recorder erased after every flight?

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Why is the maximum length of OpenWrt’s root password 8 characters?

FPGA - DIY Programming

Scaling a graph of a circle and the standard parabola in TikZ

What is the meaning of Triage in Cybersec world?

Can we generate random numbers using irrational numbers like π and e?

Does the shape of a die affect the probability of a number being rolled?

Can you compress metal and what would be the consequences?

Why isn't airport relocation done gradually?

How to support a colleague who finds meetings extremely tiring?

Geography at the pixel level

Why do UK politicians seemingly ignore opinion polls on Brexit?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Why was M87 targetted for the Event Horizon Telescope instead of Sagittarius A*?

Is bread bad for ducks?

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

Origin of "cooter" meaning "vagina"

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Why is my custom API endpoint not working?

Can a flute soloist sit?

How come people say “Would of”?

How to manage monthly salary

How are Package `Private` variables accessed?



How to resolve the Error “Call to a member function getChildren() on null”



The 2019 Stack Overflow Developer Survey Results Are InGet subcategories of parent category when FLAT categories enabledLayered navigation on homepage in magento 1.9 Call to a member function load() on a non-object in Error OccuredHow would I add “Brand” to the layered navigation without having to add the attribute to the productHow To call 'sidebar.phtml' in cart pop upHow to set dynamic width for the ul by postitioning it properly?How to align the ul li perfectly columnwise?When i call $this->loadLayout(); ite return error on catalogsearchGetting error : Fatal error: Call to a member function setLayer() on a non-object inMagento 1: Custom layer block not showing categoriesjQuery got no function after AJAX call





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I wish to display the level1 and level2 subcategories of current active category in layered navigation in list page. So I gave the below code in catalog/category/view.phtml :



 <div class="sidebar-block">
<?php
$html = '';

$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

$counter = 1;
$childrenCount = $children->count();
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
<div class="block-content clearfix">
<ul class="subcategories">
<?php foreach ($categories as $category): ?>
<?php


foreach ($children as $child) {
$child->setLevel($childLevel);
$child->setIsFirst($counter == 1);
$child->setIsLast($counter == $childrenCount);
$child->setPositionClass($itemPositionClassPrefix . $counter);

$outermostClassCode = 'level'. $childLevel;
$_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

$html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';

$html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';

if (!empty($childrenWrapClass)) {
$html .= '<div class="'. $childrenWrapClass .'">';
}

$nextChildLevel = $childLevel + 1;

if (!empty($_hasChildren)) {
$html .= '<ul class="level'. $childLevel .'">';
$html .= $this->render($child, $childrenWrapClass);
$html .= '</ul>';
}

if (!empty($childrenWrapClass)) {
$html .= '</div>';
}

$html .= '</li>';

$counter++;
} ?>
<?php endforeach; ?>
</ul>
</div>
</div>


am getting the error like Call to a member function getChildren() on null
How to resolve this? What should be done.Or is this approach wrong? Help please. am stuck.










share|improve this question














bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    0















    I wish to display the level1 and level2 subcategories of current active category in layered navigation in list page. So I gave the below code in catalog/category/view.phtml :



     <div class="sidebar-block">
    <?php
    $html = '';

    $children = $menuTree->getChildren();
    $parentLevel = $menuTree->getLevel();
    $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

    $counter = 1;
    $childrenCount = $children->count();
    $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
    $categories = $category->getCollection()
    ->addAttributeToSelect(array('name', 'thumbnail'))
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($category->getChildren())
    ?>
    <div class="block-content clearfix">
    <ul class="subcategories">
    <?php foreach ($categories as $category): ?>
    <?php


    foreach ($children as $child) {
    $child->setLevel($childLevel);
    $child->setIsFirst($counter == 1);
    $child->setIsLast($counter == $childrenCount);
    $child->setPositionClass($itemPositionClassPrefix . $counter);

    $outermostClassCode = 'level'. $childLevel;
    $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

    $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';

    $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';

    if (!empty($childrenWrapClass)) {
    $html .= '<div class="'. $childrenWrapClass .'">';
    }

    $nextChildLevel = $childLevel + 1;

    if (!empty($_hasChildren)) {
    $html .= '<ul class="level'. $childLevel .'">';
    $html .= $this->render($child, $childrenWrapClass);
    $html .= '</ul>';
    }

    if (!empty($childrenWrapClass)) {
    $html .= '</div>';
    }

    $html .= '</li>';

    $counter++;
    } ?>
    <?php endforeach; ?>
    </ul>
    </div>
    </div>


    am getting the error like Call to a member function getChildren() on null
    How to resolve this? What should be done.Or is this approach wrong? Help please. am stuck.










    share|improve this question














    bumped to the homepage by Community 3 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I wish to display the level1 and level2 subcategories of current active category in layered navigation in list page. So I gave the below code in catalog/category/view.phtml :



       <div class="sidebar-block">
      <?php
      $html = '';

      $children = $menuTree->getChildren();
      $parentLevel = $menuTree->getLevel();
      $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

      $counter = 1;
      $childrenCount = $children->count();
      $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
      $categories = $category->getCollection()
      ->addAttributeToSelect(array('name', 'thumbnail'))
      ->addAttributeToFilter('is_active', 1)
      ->addIdFilter($category->getChildren())
      ?>
      <div class="block-content clearfix">
      <ul class="subcategories">
      <?php foreach ($categories as $category): ?>
      <?php


      foreach ($children as $child) {
      $child->setLevel($childLevel);
      $child->setIsFirst($counter == 1);
      $child->setIsLast($counter == $childrenCount);
      $child->setPositionClass($itemPositionClassPrefix . $counter);

      $outermostClassCode = 'level'. $childLevel;
      $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

      $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';

      $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';

      if (!empty($childrenWrapClass)) {
      $html .= '<div class="'. $childrenWrapClass .'">';
      }

      $nextChildLevel = $childLevel + 1;

      if (!empty($_hasChildren)) {
      $html .= '<ul class="level'. $childLevel .'">';
      $html .= $this->render($child, $childrenWrapClass);
      $html .= '</ul>';
      }

      if (!empty($childrenWrapClass)) {
      $html .= '</div>';
      }

      $html .= '</li>';

      $counter++;
      } ?>
      <?php endforeach; ?>
      </ul>
      </div>
      </div>


      am getting the error like Call to a member function getChildren() on null
      How to resolve this? What should be done.Or is this approach wrong? Help please. am stuck.










      share|improve this question














      I wish to display the level1 and level2 subcategories of current active category in layered navigation in list page. So I gave the below code in catalog/category/view.phtml :



       <div class="sidebar-block">
      <?php
      $html = '';

      $children = $menuTree->getChildren();
      $parentLevel = $menuTree->getLevel();
      $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

      $counter = 1;
      $childrenCount = $children->count();
      $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
      $categories = $category->getCollection()
      ->addAttributeToSelect(array('name', 'thumbnail'))
      ->addAttributeToFilter('is_active', 1)
      ->addIdFilter($category->getChildren())
      ?>
      <div class="block-content clearfix">
      <ul class="subcategories">
      <?php foreach ($categories as $category): ?>
      <?php


      foreach ($children as $child) {
      $child->setLevel($childLevel);
      $child->setIsFirst($counter == 1);
      $child->setIsLast($counter == $childrenCount);
      $child->setPositionClass($itemPositionClassPrefix . $counter);

      $outermostClassCode = 'level'. $childLevel;
      $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

      $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';

      $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'. $this->escapeHtml($this->__($child->getName())) .'</a>';

      if (!empty($childrenWrapClass)) {
      $html .= '<div class="'. $childrenWrapClass .'">';
      }

      $nextChildLevel = $childLevel + 1;

      if (!empty($_hasChildren)) {
      $html .= '<ul class="level'. $childLevel .'">';
      $html .= $this->render($child, $childrenWrapClass);
      $html .= '</ul>';
      }

      if (!empty($childrenWrapClass)) {
      $html .= '</div>';
      }

      $html .= '</li>';

      $counter++;
      } ?>
      <?php endforeach; ?>
      </ul>
      </div>
      </div>


      am getting the error like Call to a member function getChildren() on null
      How to resolve this? What should be done.Or is this approach wrong? Help please. am stuck.







      layered-navigation sidebar submenu






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 18 '16 at 11:56









      RamyaRamya

      6931236




      6931236





      bumped to the homepage by Community 3 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 3 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If error says that you call function on null, first thing I would do is to check variable $category or $menuTree with print_r() or var_dump - maybe they are in fact null, which means the objects which should be under these varaibles or you think they should be, in fact are not assigned to them. Later if you detect which and if varaible is empty you should figure out way and then you can perform some changes in your code to get what you've planned.






          share|improve this answer
























          • can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

            – Ramya
            Jun 20 '16 at 10:13











          • I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

            – Bartosz Kubicki
            Jun 20 '16 at 10:43












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f121644%2fhow-to-resolve-the-error-call-to-a-member-function-getchildren-on-null%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If error says that you call function on null, first thing I would do is to check variable $category or $menuTree with print_r() or var_dump - maybe they are in fact null, which means the objects which should be under these varaibles or you think they should be, in fact are not assigned to them. Later if you detect which and if varaible is empty you should figure out way and then you can perform some changes in your code to get what you've planned.






          share|improve this answer
























          • can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

            – Ramya
            Jun 20 '16 at 10:13











          • I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

            – Bartosz Kubicki
            Jun 20 '16 at 10:43
















          0














          If error says that you call function on null, first thing I would do is to check variable $category or $menuTree with print_r() or var_dump - maybe they are in fact null, which means the objects which should be under these varaibles or you think they should be, in fact are not assigned to them. Later if you detect which and if varaible is empty you should figure out way and then you can perform some changes in your code to get what you've planned.






          share|improve this answer
























          • can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

            – Ramya
            Jun 20 '16 at 10:13











          • I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

            – Bartosz Kubicki
            Jun 20 '16 at 10:43














          0












          0








          0







          If error says that you call function on null, first thing I would do is to check variable $category or $menuTree with print_r() or var_dump - maybe they are in fact null, which means the objects which should be under these varaibles or you think they should be, in fact are not assigned to them. Later if you detect which and if varaible is empty you should figure out way and then you can perform some changes in your code to get what you've planned.






          share|improve this answer













          If error says that you call function on null, first thing I would do is to check variable $category or $menuTree with print_r() or var_dump - maybe they are in fact null, which means the objects which should be under these varaibles or you think they should be, in fact are not assigned to them. Later if you detect which and if varaible is empty you should figure out way and then you can perform some changes in your code to get what you've planned.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 18 '16 at 13:51









          Bartosz KubickiBartosz Kubicki

          1,4401037




          1,4401037













          • can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

            – Ramya
            Jun 20 '16 at 10:13











          • I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

            – Bartosz Kubicki
            Jun 20 '16 at 10:43



















          • can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

            – Ramya
            Jun 20 '16 at 10:13











          • I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

            – Bartosz Kubicki
            Jun 20 '16 at 10:43

















          can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

          – Ramya
          Jun 20 '16 at 10:13





          can you suggest a way to display level 1 and level 2 category in layered navigation in list page?

          – Ramya
          Jun 20 '16 at 10:13













          I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

          – Bartosz Kubicki
          Jun 20 '16 at 10:43





          I am not actually working on Magento 1, I don't have it even installed in raw copy, so I cannot help you now. I am sorry :(

          – Bartosz Kubicki
          Jun 20 '16 at 10:43


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f121644%2fhow-to-resolve-the-error-call-to-a-member-function-getchildren-on-null%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          迭戈·戈丁...

          A phrase ”follow into" in a context The 2019 Stack Overflow Developer Survey Results Are...

          1960s short story making fun of James Bond-style spy fiction The 2019 Stack Overflow Developer...