0

I would like to know how I can loop through recursively the entire category structure and enable every category.

1
 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 umask(0);
 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


$_categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect(array('*')
                    ->addAttributeToFilter('is_active', 0);

    foreach ($_categories as $_category){
       // if you have any issue then you many need to load the 
       // $_category = Mage::getModel('catalog/category')->load($_category->getId());
       $_category->setIsActive(1);
       $_category->save();
    }

If you have multiple stores or categories root see Get category collection from specific store

| improve this answer | |
1

I came up with the following script:

<?php

define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$category = Mage::getModel('catalog/category');
$tree     = $category->getTreeModel();
$tree->load();

$ids = $tree->getCollection()->getAllIds();

// Activate the categories
foreach ($ids as $_id) {

    $_category = Mage::getModel('catalog/category')->load($_id);

    $_category->setIsActive(1);
    $_category->save();
    echo "Enabled " . $_id . "\n";

}

?>
| improve this answer | |

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.