Magento获取所有分类列表

在这里,我会告诉你如何得到所有类别的Magento的店的名单。
你可能想显示在主页或任何CMS页面的所有类别。有不同的方式来获得类别列表。这里有一些: -

获取所有类别

下面的代码将获取所有类别(活动和非活动)存在于你的Magento店。

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*');

获取所有活动类别

下面的代码将获取所有活动的类别存在于你的Magento店。因此,过滤无效的类别。

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter();

获取主动的类别某一水平

下面的代码将获取所有活动类的某些/特定级别。在这里,

按名称类别排序

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter()
                    ->addLevelFilter(1)
                    ->addOrderField('name');

获取存储特定类别

下面的代码将获取所有活动的店面具体类别。下面的辅助函数这​​样做: -
getStoreCategories(sorted=false, asCollection=false, $toLoad=true)

$helper = Mage::helper('catalog/category');

// sorted by name, fetched as collection
$categoriesCollection = $helper->getStoreCategories('name', true, false);

// sorted by name, fetched as array
$categoriesArray = $helper->getStoreCategories('name', false, false);

希望这有助于你。谢谢。
From Mukesh Chapagain’s Blog, post Magento: Get list of all Categories

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章