[英]Loop through categories in Magento
我的Magento商店中有几个类别,想要更改其名称。 您可以遍历所有产品
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('description')
->load();
foreach($_productCollection as $_product) {
我认为也有一种方法可以遍历类别。 有没有办法做到这一点?
提前致谢!
使用以下代码,您可以遍历类别。
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
foreach($categories as $category)
{
echo $category->getName().', ';
}
要么
$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.