$categories = Mage::getModel('catalog/category')->getCollection()
        ->addAttributeToFilter('level', 2) level
        ->addAttributeToFilter('is_active', 1)
        ->addAttributeToFilter('include_in_menu', 1)
        ->addFieldToFilter('path', array('like'=> "1/$rootid/%"))

    foreach ($categories as $category) { yaddayadda() }

Calling this from a simple script in the shell directory leads to the correct result. I only get the categories that are active and included in the menu. But when it is called in the normal Magento Block for building the top navigation it somehow changes the attributes of the categories. It shows everyone and when I check the attributes via debugger or var_dump it says "included_in_menu" (or "is_active") is 1. But it's not! It's correctly set in the backend and getting this collection via shell it says the values are 0. I cleared the caches endless times and saved the categories multiple times.

What can possibly cause this?

  • Did you try to flush the cache and reindex ? – Raphael at Digital Pianism Feb 8 '17 at 15:02
  • Countless times. – alobeejay Feb 8 '17 at 15:02
  • Are you sure the category is associated to the store you're testing ? – Raphael at Digital Pianism Feb 8 '17 at 15:03
  • Yes. I checked the store id and the category id. Everything is identical in the shell script and the block code. Edit: Ok, no it isn't...the store view differs. It's working now...stupid....thank you very much. – alobeejay Feb 8 '17 at 15:04

Ok, thanks to Raphael at Digital Pianism I checked the category in the backend again and realized the value was set in another store view. The shell script accessed another one than the magento block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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