0

Thanks guys for the help in getting the cat ids in magento.

Found this script to mass enable categories based on IDs

<?php setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$file = fopen(MAGENTO . "/var/import/categoriesToEnable.csv", 'r');
while (($line = fgetcsv($file)) !== FALSE) {
$cats = explode(",",$line[1]);
foreach ($cats as $cat) {
$newcats[$cat] = true;
}
}
// Activate the categories it is in foreach ($newcats as $cat=>$value) {
if ($value && !empty($cat)) {
try {
$_category = Mage::getModel('catalog/category')->load($cat);
if ($_category->getIsActive() === "0" || !$_category->getIsActive()) {
$_category->setIsActive(1);
$_category->save();
echo "
Enabled ".$_category->getName();
unset($_category);
}
} catch(Exception $e) {
echo " Caught Cat Insert exception: ", $e->getMessage();
}
}
 }
?>

Get an error when trying to run it

Fatal error: Call to undefined function setCurrentStore() in /var/www/vhosts/***********/httpdocs/quick_enableCats.php on line 2
0

Try using this way:

<?php 
require_once('app/Mage.php');
umask(0);
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$file = fopen(MAGENTO . "/var/import/categoriesToEnable.csv", 'r');
while (($line = fgetcsv($file)) !== FALSE) {
    $cats = explode(",",$line[1]);
    foreach ($cats as $cat) {
        $newcats[$cat] = true;
    }
}
// Activate the categories it is in foreach ($newcats as $cat=>$value) {
if ($value && !empty($cat)) {
    try {
        $_category = Mage::getModel('catalog/category')->load($cat);
        if ($_category->getIsActive() === "0" || !$_category->getIsActive()) {
            $_category->setIsActive(1);
            $_category->save();
            echo "Enabled ".$_category->getName();
            unset($_category);
        }
    } catch(Exception $e) {
        echo " Caught Cat Insert exception: ", $e->getMessage();
    }
}
?>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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