[英]Loop through categories in Magento
I have several categories in my Magento shop and want to change their name. 我的Magento商店中有几个类别,想要更改其名称。 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.