Last active
August 4, 2016 00:57
-
-
Save tuanphpvn/7102446cfc7e6b880d59 to your computer and use it in GitHub Desktop.
Delete category with a name #Magento #Category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$deleteCatByName = function($catname) { | |
$category = Mage::getModel('catalog/category'); | |
$tree = $category->getTreeModel(); | |
$tree->load(); | |
$ids = $tree->getCollection()->getAllIds(); | |
if ($ids){ | |
foreach ($ids as $id){ | |
$cat = Mage::getModel('catalog/category'); | |
$cat->load($id); | |
$name = $cat->getName(); | |
if($name === $catname) { | |
$cat->delete(); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment