I have several categories in my Magento shop and want to change their name. As you can loop through all products
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('description')
->load();
foreach($_productCollection as $_product) {
I thought there is a way to loop through categories too. Is there a way to do that?
Thanks in advance!
Using following code you can loop through categories.
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
foreach($categories as $category)
{
echo $category->getName().', ';
}
OR
$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);
$entity_id = $cat->getId();
$name = $cat->getName();
$url_key = $cat->getUrlKey();
$url_path = $cat->getUrlPath();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.