循环遍历 Magento 中的类别
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();
}
}
我的 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();
}
}