Magento Expert Forum - Improve your Magento experience
-
.How to filtrate Magento category collection by rank?
Sometimes you need to get a list of all categories with a particular level for a custom navigation menu. This can be done as follows:
$model=Mage::getModel('catalog/category');
$categories=$model->getCollection()->addLevelFilter(2)
->addAttributeToSelect('*')->addIsActiveFilter();
However, this is not always correct. I think I should explain why, right?
If I will enter request to a base I will get the following: SELECT `main_table`.* FROM `catalog_category_flat_store_1` AS `main_table` WHERE (main_table.level <= 2) AND (is_active = ’1′)
It is very visible that condition <= is in use, what doesn’t fit, because filtering categories of 3 rd level we will also get categories with 2 nd level.
Due to this we should do filtration in the following way:
$categories=$model->getCollection()->addAttributeToFilter('level',2)
->addAttributeToSelect('*')->addIsActiveFilter();
After this we can do whatever we want with the collection.
Any questions? Ask here
View more threads in the same category:
- Portable rv air conditioner
- Transforming Karachi's Skylines with Fiber Shades
- Unveiling the Power of E911 Solutions Enhancing Caller Identification
- List of Top 10 Interior Designers in Pakistan
- buy registered drivers license online(legitcleandocs.com)passport,IELTS certific
- Malaysia Visit Visa from Dubai
- Buy Passport,Driver License,Age & ID Card,(Whatsapp:.......: +1 (551) 239-2904) Visas
- 슬롯사이트 추천 - 인터넷슬롯링크 2024 best 온라인슬롯
- Buy Passport,Driver License,Age & ID Card,(Whatsapp:.......: +1 (551) 239-2904) Visas
- Buy Passport,Driver License,Age & ID Card,Visas and Undetected Counterfeit Money. Ema
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks