How to get a category listing from Magento?

后端 未结 8 2067
野性不改
野性不改 2021-01-31 22:33

I want to create a page in Magento that shows a visual representation of the categories.. example

CATEGORY
 product 1
 product 2

ANOTHER CATEGORY
 product 3
         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 23:10

    From code found in an SEO related class (Mage_Catalog_Block_Seo_Sitemap_Category)

    $helper     = Mage::helper('catalog/category');
    $collection = $helper->getStoreCategories('name', true, false);
    $array      = $helper->getStoreCategories('name', false, false);
    

    Try to forget that it's a database that's powering your store, and instead concentrate on using the objects that the Magento system provides.

    For example, I had no no idea how to get a list of categories. However, I grepped through the Mage codebase with

    grep -i -r -E 'class.+?category'
    

    Which returned a list of around 30 classes. Scrolling through those, it was relatively easy to guess which objects might have methods or need to make method calls that would grab the categories.

提交回复
热议问题