Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 3
Magento 1.5 Admin - categories tree for products does not auto-expand to show product categories
 
ceceres
Jr. Member
 
Total Posts:  3
Joined:  2011-08-14
 
SonicE - 23 August 2011 07:07 AM

I think the issue is in another function in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
--snip--

Thanks, SonicE. This did the trick for ver. 1.6.1.0 CE

 
Magento Community Magento Community
Magento Community
Magento Community
 
andymelichar
Jr. Member
 
Total Posts:  6
Joined:  2009-05-13
 
SonicE - 23 August 2011 07:07 AM

I think the issue is in another function in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php

//------>START FIX
            if ($storeId{
                $store 
Mage::app()->getStore($storeId);
                
$rootId $store->getRootCategoryId();
                
$ids $this->getSelectedCategoriesPathIds($rootId); // Added this line, and commented below
            
}
            
else {
                $rootId 
Mage_Catalog_Model_Category::TREE_ROOT_ID;
                
$ids $this->getSelectedCategoriesPathIds(); // Added this line without passing $rootId , and commented below
            
}

            
//$ids = $this->getSelectedCategoriesPathIds($rootId); //Commented this line and moved up
//------>END FIX

Worked for me. THANKS A MILLION!

 
Magento Community Magento Community
Magento Community
Magento Community
 
LoriKB
Jr. Member
 
Total Posts:  8
Joined:  2011-04-08
 

I am having the opposite issue most people are. My category trees work fine on the edit product pages but in the manage categories page the tree menus do not work.

I have noticed tree menus not working in other areas of the site such as when I try to add a file on a cms page any sub folders I created do not show and I cannot expand the menu.

Any one have any ideas?
Lori

 
Magento Community Magento Community
Magento Community
Magento Community
 
redsy
Jr. Member
 
Total Posts:  17
Joined:  2011-06-04
 

Thought I’d add my 2 pence, as I have been experiencing a problem with my category tree.

I could add new categories or sub-categories within the “Manage Categories”, but when I was in the Product Edit pages I couldn’t open up any sub categories.

I tried all the fixes listed and nothing helped.

I tried a different browser and it worked fine with no fixes.

Magento is recently upgraded to 1.6.1.0

Error using Firefox 7.0.1

No Error using IE 9.0.8

 
Magento Community Magento Community
Magento Community
Magento Community
 
redsy
Jr. Member
 
Total Posts:  17
Joined:  2011-06-04
 

Also upgraded to Firefox 8.0 and it’s still not working.

Tested in Chrome 15.0 and it appears fine.

This didn’t happen in 1.5.1.0 in Firefox and I haven’t installed anything else I wonder how widespread this bug is…

Edit sorry ignore my two above comments it’s working fine in Firefox on my home computer, just be something erronous on my work computer

 
Magento Community Magento Community
Magento Community
Magento Community
 
Feggel
Jr. Member
 
Total Posts:  10
Joined:  2008-06-03
 
redsy - 15 November 2011 08:30 AM

Thought I’d add my 2 pence, as I have been experiencing a problem with my category tree.

I could add new categories or sub-categories within the “Manage Categories”, but when I was in the Product Edit pages I couldn’t open up any sub categories.

I tried all the fixes listed and nothing helped.

I tried a different browser and it worked fine with no fixes.

Magento is recently upgraded to 1.6.1.0

Error using Firefox 7.0.1

No Error using IE 9.0.8

Same issue, using Firefox 8.0.1. When switching to Safari 5.0.1 no problems..

A fix would be nice, because I don’t always have access to Safari..

 
Magento Community Magento Community
Magento Community
Magento Community
 
ligrex
Jr. Member
 
Total Posts:  27
Joined:  2008-09-25
 

Great job!!!
It works for me!!

Thankyou very very much!!!!!!

SonicE - 23 August 2011 07:07 AM

I think the issue is in another function in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php

public function getRoot($parentNodeCategory=null$recursionLevel=3)
    
{
        
if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) {
            
return $this->getNode($parentNodeCategory$recursionLevel);
        
}
        $root 
Mage::registry('root');
        if (
is_null($root)) {
            $storeId 
= (int) $this->getRequest()->getParam('store');

            if (
$storeId{
                $store 
Mage::app()->getStore($storeId);
                
$rootId $store->getRootCategoryId();
            
}
            
else {
                $rootId 
Mage_Catalog_Model_Category::TREE_ROOT_ID;
            
}

            $ids 
$this->getSelectedCategoriesPathIds($rootId);
            
$tree Mage::getResourceSingleton('catalog/category_tree')
                ->
loadByIds($idsfalsefalse);

            if (
$this->getCategory()) {
                $tree
->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
            
}

            $tree
->addCollectionData($this->getCategoryCollection());

            
$root $tree->getNodeById($rootId);

            if (
$root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setIsVisible(true);
                if (
$this->isReadonly()) {
                    $root
->setDisabled(true);
                
}
            }
            
elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setName(Mage::helper('catalog')->__('Root'));
            
}

            Mage
::register('root'$root);
        
}

        
return $root;
    
}

Take a look at
$storeId = (int) $this->getRequest()->getParam('store');

On a single store view it always returns NULL and then the $rootId is not set correctly by calling getSelectedCategoriesPathIdss($rootId)

My fix is:

public function getRoot($parentNodeCategory=null$recursionLevel=3)
    
{
        
if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) {
            
return $this->getNode($parentNodeCategory$recursionLevel);
        
}
        $root 
Mage::registry('root');
        if (
is_null($root)) {
            $storeId 
= (int) $this->getRequest()->getParam('store');
//------>START FIX
            
if ($storeId{
                $store 
Mage::app()->getStore($storeId);
                
$rootId $store->getRootCategoryId();
                
$ids $this->getSelectedCategoriesPathIds($rootId); // Added this line, and commented below
            
}
            
else {
                $rootId 
Mage_Catalog_Model_Category::TREE_ROOT_ID;
                
$ids $this->getSelectedCategoriesPathIds(); // Added this line without passing $rootId , and commented below
            
}

            
//$ids = $this->getSelectedCategoriesPathIds($rootId); //Commented this line and moved up
//------>END FIX         
            
$tree Mage::getResourceSingleton('catalog/category_tree')
                ->
loadByIds($idsfalsefalse);

            if (
$this->getCategory()) {
                $tree
->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
            
}

            $tree
->addCollectionData($this->getCategoryCollection());

            
$root $tree->getNodeById($rootId);

            if (
$root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setIsVisible(true);
                if (
$this->isReadonly()) {
                    $root
->setDisabled(true);
                
}
            }
            
elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setName(Mage::helper('catalog')->__('Root'));
            
}

            Mage
::register('root'$root);
        
}

        
return $root;
    
}

Please correct me if all this is wrong
 
Magento Community Magento Community
Magento Community
Magento Community
 
gsorry
Jr. Member
 
Avatar
Total Posts:  1
Joined:  2010-02-01
Kragujevac
 

In magento 1.6 open app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
find method at line 75:

public function getRootNode()
    
{
//        $root = parent::getRoot();
        
$root $this->getRoot();
        if (
$root && in_array($root->getId(), $this->getCategoryIds())) {
            $root
->setChecked(true);
        
}
        
return $root;
    
}
and change it in this:
public function getRootNode()
{
$root = parent::getRoot();
// $root = $this->getRoot();
if ($root && in_array($root->getId(), $this->getCategoryIds())) {
$root->setChecked(true);
}
return $root;
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
zigojacko
Jr. Member
 
Total Posts:  13
Joined:  2010-09-05
 
SonicE - 23 August 2011 07:07 AM

I think the issue is in another function in app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php

public function getRoot($parentNodeCategory=null$recursionLevel=3)
    
{
        
if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) {
            
return $this->getNode($parentNodeCategory$recursionLevel);
        
}
        $root 
Mage::registry('root');
        if (
is_null($root)) {
            $storeId 
= (int) $this->getRequest()->getParam('store');

            if (
$storeId{
                $store 
Mage::app()->getStore($storeId);
                
$rootId $store->getRootCategoryId();
            
}
            
else {
                $rootId 
Mage_Catalog_Model_Category::TREE_ROOT_ID;
            
}

            $ids 
$this->getSelectedCategoriesPathIds($rootId);
            
$tree Mage::getResourceSingleton('catalog/category_tree')
                ->
loadByIds($idsfalsefalse);

            if (
$this->getCategory()) {
                $tree
->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
            
}

            $tree
->addCollectionData($this->getCategoryCollection());

            
$root $tree->getNodeById($rootId);

            if (
$root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setIsVisible(true);
                if (
$this->isReadonly()) {
                    $root
->setDisabled(true);
                
}
            }
            
elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setName(Mage::helper('catalog')->__('Root'));
            
}

            Mage
::register('root'$root);
        
}

        
return $root;
    
}

Take a look at
$storeId = (int) $this->getRequest()->getParam('store');

On a single store view it always returns NULL and then the $rootId is not set correctly by calling getSelectedCategoriesPathIdss($rootId)

My fix is:

public function getRoot($parentNodeCategory=null$recursionLevel=3)
    
{
        
if (!is_null($parentNodeCategory) && $parentNodeCategory->getId()) {
            
return $this->getNode($parentNodeCategory$recursionLevel);
        
}
        $root 
Mage::registry('root');
        if (
is_null($root)) {
            $storeId 
= (int) $this->getRequest()->getParam('store');
//------>START FIX
            
if ($storeId{
                $store 
Mage::app()->getStore($storeId);
                
$rootId $store->getRootCategoryId();
                
$ids $this->getSelectedCategoriesPathIds($rootId); // Added this line, and commented below
            
}
            
else {
                $rootId 
Mage_Catalog_Model_Category::TREE_ROOT_ID;
                
$ids $this->getSelectedCategoriesPathIds(); // Added this line without passing $rootId , and commented below
            
}

            
//$ids = $this->getSelectedCategoriesPathIds($rootId); //Commented this line and moved up
//------>END FIX         
            
$tree Mage::getResourceSingleton('catalog/category_tree')
                ->
loadByIds($idsfalsefalse);

            if (
$this->getCategory()) {
                $tree
->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
            
}

            $tree
->addCollectionData($this->getCategoryCollection());

            
$root $tree->getNodeById($rootId);

            if (
$root && $rootId != Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setIsVisible(true);
                if (
$this->isReadonly()) {
                    $root
->setDisabled(true);
                
}
            }
            
elseif($root && $root->getId() == Mage_Catalog_Model_Category::TREE_ROOT_ID{
                $root
->setName(Mage::helper('catalog')->__('Root'));
            
}

            Mage
::register('root'$root);
        
}

        
return $root;
    
}

Please correct me if all this is wrong

After a recent upgrade from Magento 1.4 to 1.6, we noticed that the product pages weren’t displaying the category tree in the Categories tab as expected (might possible have been after we updated prototype.js too).

Your fix above solved the problem - thanks smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
WebSokol
Jr. Member
 
Total Posts:  16
Joined:  2011-04-17
 

It worked for me. Magento 1.7

THANKS !!!

dlefers - 20 July 2011 11:29 PM

Just discovered this bug when i was attended to it by one of my clients.

The problem does not seem to be PHP related. Since the Ajax call is returning the correct JSON response for the parents subcategories. Simple conclusion is that is has something to do with the related javascript parsing all the subcategories in the tree.

I`m not sure why but i got the solution for my case:

Open:

app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml

Search for the instantiation of the new TreePanel around line: 65.

In the settings, set animate:true to animate:false. Find the example attached below:

var tree = new Ext.tree.TreePanel('product-categories'{
        animate
:false,
        
loadercategoryLoader,
        
enableDD:false,
        
containerScrolltrue,
        
rootUIProviderExt.tree.CheckboxNodeUI,
        
selModel: new Ext.tree.CheckNodeMultiSelectionModel(),
        
rootVisible'<?php echo $this->getRootNode()->getIsVisible() ?>'
    
});

Clear the Admin cache files, reload the product edit page and go to the categories tab, thats it!

Anyone has a clue what is causing the setting “animate” to not parse any childnodes?
 
Magento Community Magento Community
Magento Community
Magento Community
 
benz001
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2009-02-05
Sydney
 

It looks like there’s another bug in 1.7, the patch to getRoot() is no longer fixing this for me.

Has anyone got this working on 1.7 with a single store setup?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alexgriga
Jr. Member
 
Total Posts:  4
Joined:  2010-07-19
 

This is how I solved this issue in Magento 1.7.0.0:

I added some code in the file:
app\design\adminhtml\default\default\template\catalog\product\edit\categories.phtml

On line 32 there is this code:

<input type="hidden" name="category_ids" id="product_categories" 
value="<?php echo $this->getIdsString() ?>">
After that line, add:
<input type="hidden" name="category_ids_path" id="product_categories_path" 
value="<?php echo implode(',', $this->getSelectedCategoriesPathIds()); ?>">
This will prepare a new hidden input element with the list of all the category ids in the paths that need expanded.

Around line 60 there is an event observer, already mentioned in this thread.
To expand the neccessary nodes, add to the event observer the code:

categoryLoader.on("load", function(treeLoadernodeconfig{
        varienWindowOnload
();
        
node.childNodes.each(function(e){
            
if($('product_categories_path').value.split(',').indexOf(e.attributes.id)!=-1)
            
e.expand();
        
})
    
});

This will expand the product categories with JavaScript and Ajax.
Ideally the nodes should be expanded at the PHP level, but this solution is enough for me.
Hope it helps. If anyone has any questions please post here.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bepixeld
Jr. Member
 
Total Posts:  2
Joined:  2009-04-20
 

I found another solution for 1.7.0.2

copy /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
to /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
So we don\\\’t edit core files.

Edit /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
the function _isParentSelectedCategory() around line 190
replace the code:

...
        
$allChildren $node->getAllChildren();
        if (
$allChildren{
            $selectedCategoryIds 
$this->getCategoryIds();
            
$allChildrenArr explode(\\\',\\\'$allChildren);
...

with:

...
        
$allChildren $node->getAllChildNodes();
        if (
$allChildren{
            $selectedCategoryIds 
$this->getCategoryIds();
            
$allChildrenArr array_keys($allChildren);
...
$node->getAllChildren() is in my cases alway null, so i get no result.
In $node->getAllChildNodes() we get the category entity_ids as keys of the array, so we can use this.

And then in function getSelectedCategoriesPathIds() around line 275
replace the code:

...
        if (
$rootId{
            $collection
->addFieldToFilter(\\\'parent_id\\\'$rootId);
        
else {
            $collection
->addFieldToFilter(\\\'entity_id\\\', array(\\\'in\\\'=>$categoryIds));
        
}
...

with:

...
        
$collection->addFieldToFilter(\\\'entity_id\\\', array(\\\'in\\\'=>$categoryIds));
...
The collection-filter with $rootId is not working in some cases for me.
But the collection-filter $categoryIds is always working. In single store and multi store.
This solution expands the nodes in PHP level.
I hope this helps someone.
 
Magento Community Magento Community
Magento Community
Magento Community
 
majorpain
Jr. Member
 
Avatar
Total Posts:  5
Joined:  2012-08-16
 

Having the same issue here with 1.7.0.2.

Things i did:

1- All that everybody said here with 0% sucess.
2- Put back inside the problematic cattegories some subcattegory i remember moving to other cattegory (worked like a charm, but i had to test a few subcattegories before finding the one that was messing it all up).

Cheers!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vishal Surani
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2010-04-13
 

Thanks Wyomind,

categoryLoader.on("load", function(treeLoadernodeconfig{
        varienWindowOnload
();
        
node.childNodes.each(function(e){
          
if($('product_categories').value.split(',').indexOf(e.attributes.id)!=-1)
            
e.getUI().check(true);
        
})
    
});

This is working for me in magento 1.7.0.2

Warm Regards,

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 3