get last level category name of a product in magento

好久不见. 提交于 2019-12-24 23:33:10

问题


I am trying to get only which category name that assigned a product and which category's have not any sub-category.

E.g :

Category
                -> Sub-category 1
                -> Sub-category 2
                -> Sub-category 3 
                                  -> Sub-sub-category 1
                                  -> sub-Sub-category 2
                                                        -> product 1
                                                        -> product 2

The above example , I want to get only sub-sub-category 2.


回答1:


you can try this

 $categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter()
                   ->addAttributeToFilter('level',3)


来源:https://stackoverflow.com/questions/20926118/get-last-level-category-name-of-a-product-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!