1

I am working on a webshop in Magento.
When I try to change an existing configurable product to another category, I only get to see Root Catalog:

enter image description here

This is kind of awkward. As I CAN choose other categories when adding a new product.

I found it quite difficult to find any solutions for this.
Does anyone have any advice, suggestions or solutions for this?
I am willing to code in PHP if I had to... But I'd like to do as less as possible changes to core files.
Thanks in advance.

UPDATE

I am using the following extensions:

  • Afterpay
  • ImaClean
  • FlatShipping5
  • Moneybookers?
  • Deleteorder from Raveinfosys
  • Exporter from Raveinfosys
  • Zopim livechat
  • MyParcel

And some functions from the SNS Toronto theme:

  • Ajaxcart
  • Ajaxfilter
  • ProductList
  • Producttabs
  • Quickview
  • RevolutionSlider
  • Slider
  • Toronto
  • Twitter

UPDATE 1

I noticed that when I am adding a new product, I can select the categories, but when I want to update a product, it seems to have this problem. Regardless if imported or not.

6
  • Can you list the third party modules you are using?
    – scrowler
    Jun 20, 2016 at 9:17
  • @RobbieAverill, Thank you, Hopefully, I have listed all extensions. Check my edited question.
    – Sj03rs
    Jun 20, 2016 at 9:26
  • @Sj03rs does that happen if you disable all 3rd party extensions ? Jun 20, 2016 at 10:49
  • 1
    @RaphaelatDigitalPianism, Thank you for the suggestion. I disabled all third party extensions. But unfortunately, this did not work. Any other suggestion?
    – Sj03rs
    Jun 20, 2016 at 11:14
  • 1
    @RaphaelatDigitalPianism, Then the category hierarchy works. The products which are having the problem are imported ones. It used to be fine. But "suddenly" it bugged out. I can't really go into detail as I can't really recall all the things that changed on the website. I have been making Magento stores the same way and never encountered the problem.
    – Sj03rs
    Jun 20, 2016 at 11:32

2 Answers 2

2
+50

I have a pretty strong feeling i have experienced this issue before, and at that time, i wrote a little mockup to verify and or fix the issue. This is based on my assumption.

Wrong category children count

At some point, magento checks the amount of "children" a category has and stores this in the database. If the category "children_count" does not equal the real count, Magento will not show these children in the tree. My guess is that your root category has a children count of zero due to some module, index action went wrong, core hacks or anything that disturbs this process. I wrote a gist a couple of months ago. It basically loops through all the category's for a store and counts their children. If the count value from the database does not equal the real children count, it will show you in the frontend table that it needs fixing. i wrote a little frontend at that time so it would be easier to use and give a visual of the extend of the problem.

verify your issue with this script

Drop this script in your document root and load it in your browser. It won't modify anything as long as $processValues is set to false (by default). If you see category's that needs fixing, put $processValues to true and load it again. Do this for every store you have. It will be fixed automatically and you'll see the result of the repaired "children_count" values.

note

Note that this is a dev script, the sidebar might not work and never use this on a production site and always make a backup first!

Please keep me up to date if it helped, i would like to learn more about this issue and extend this answer with some facts.

Category children count fix

https://gist.github.com/frosit/288bbb263b55c4dc8796fc79aeeb86df

3
  • Oh my days... This worked perfectly! Thank you so much! Have been struggling for a damn of a long time! I just changed the $processValues variable to true and it showed everything it fixed. And looked at the categories and they appeared again! Amazing stuff. Thank you a billion times! :D
    – Sj03rs
    Jun 27, 2016 at 8:20
  • I'm glad to hear that :), please note, that i don't know what exactly causes this and i'm eager to find out. If the issue returns or you find out what causes it, i would really appreciate it to be notified.
    – FROSIT
    Jun 28, 2016 at 11:12
  • When I find what causes it, I will notify you. Thanks!
    – Sj03rs
    Jun 28, 2016 at 11:31
2

Here's my assumption.

As your problem only happens with imported products, I'm pretty sure those buggy products have been assigned to root categories that don't exist anymore or to a store that does not have a proper category tree.

Now, how to debug that:

The category tree you can see usually is generated by the app/design/adminhtml/default/default/template/catalog/product/edit/categories.phtml by the Ext.tree.TreeNode JS library.

The JSON used to generate this tree (and thus containing the list of categories) is retrieved by the getTreeJson() method from Mage_Adminhtml_Block_Catalog_Category_Tree :

public function getTreeJson($parenNodeCategory=null)
{
    $rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
    $json = Mage::helper('core')->jsonEncode(isset($rootArray['children']) ? $rootArray['children'] : array());
    return $json;
}

Debugging

The first test I would do in your case would be to test what the data here are.

So enable the logs and modify the method like this:

public function getTreeJson($parenNodeCategory=null)
{
    Mage::log($parenNodeCategory);
    Mage::log($this->getRoot($parenNodeCategory));
    $rootArray = $this->_getNodeJson($this->getRoot($parenNodeCategory));
    $json = Mage::helper('core')->jsonEncode(isset($rootArray['children']) ? $rootArray['children'] : array());
    return $json;
}

Now, reload your product page and get the corresponding data logged under var/log/system.log .

Repeat the step with a product that works and compare the results.

4
  • Thank you, I will take a look at it. I will give results back when I'm done. Thanks again :D
    – Sj03rs
    Jun 20, 2016 at 12:11
  • Do you have any suggestion where I need to look? Because this generates a result of 87000 lines. I am sorry, I don't have a lot of experience in this.
    – Sj03rs
    Jun 20, 2016 at 12:34
  • Comment Mage::log($this->getRoot($parenNodeCategory)); and compare the result of Mage::log($parenNodeCategory); Jun 20, 2016 at 12:54
  • Result of the log: 2016-06-20T13:12:58+00:00 DEBUG (7): Now I see that with newly (manually) added products, it also appears to have this problem. I can only select category when creating a new product, not updating an existing one. I will make this more clear in the update of my answer.
    – Sj03rs
    Jun 20, 2016 at 13:17

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.