tuan
8/10/2015 - 9:27 PM

Delete category with a name #Magento #Category

Delete category with a name #Magento #Category

<?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();
            }
        }
    }
};