0

Magento 1.7.0.2. I don't use flat category/products structure.

Take a look at file app/code/core/Mage/Catalog/Block/Navigation.php.

function _renderCategoryMenuItemHtml:

// get all children
if (Mage::helper('catalog/category_flat')->isEnabled()) {
     $children = (array)$category->getChildrenNodes();
     $childrenCount = count($children);
} else {
     // category is instance of Mage_Catalog_Model_Category
     $children = $category->getChildren(); // return string
     $childrenCount = $children->count();
}

function getChildren of Mage_Catalog_Model_Category object:

/**
  * Retrieve children ids comma separated
  *
  * @return string
  */
  public function getChildren()
  {
      return implode(',', $this->getResource()->getChildren($this, false));
  }

The question is - how we can call $children->count() if $children is a string? Is this a bug?

2 Answers 2

1

This is not a bug. If the flat category is not enabled then the $category var you have in the block you specified is not an instance of Mage_Catalog_Model_Category. It's an instance of Varien_Data_Tree_Node and the method getChildren() looks like this:

/**
     * Retrieve node children collection
     *
     * @return Varien_Data_Tree_Node_Collection
     */
    public function getChildren()
    {
        return $this->_childNodes;
    }

I know it doesn't say much but in the comment you can see it returns an instance of Varien_Data_Tree_Node_Collection that has a count() method...so everything is OK.
And by the way, in CE 1.7+ this block is not used anymore. This is used to add the categories to the menu: Mage_Catalog_Model_Observer::addCatalogToTopmenuItems().

0

From my understanding PHP's implode will return a string.

Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

If your wanting a count, explode the returned imploded value from getChildren() and then count the array elements.

1
  • I understand that, but these are magento core files. So this is magento bug.... And I didn't find any information about this bug and that is strange...
    – Anthony
    Commented Apr 30, 2013 at 21:10

Your Answer

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

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