Skip to content

Instantly share code, notes, and snippets.

@tuanphpvn
Last active August 4, 2016 00:37
Show Gist options
  • Save tuanphpvn/a1290366defa9759f26b to your computer and use it in GitHub Desktop.
Save tuanphpvn/a1290366defa9759f26b to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment