tuan
9/8/2015 - 12:05 PM

Delete all category Level 2 (Root is Level 1)

Delete all category Level 2 (Root is Level 1)

<?php

$deleteAllCatChildren = function($catname) {

    $rootCategoryObj = Mage::getModel('catalog/category')->loadByAttribute('name', $catname);
    $collection = Mage::getModel('catalog/category')
        ->getCollection()
        ->addPathsFilter($rootCategoryObj->getPath().'/');

    foreach($collection as $catObj) {
        $catObj->delete();
    }

};

$deleteAllCatChildren('Root');