With flat tables turned off, how can I get a category collection from a specific store view ?

I have tried the following:


But it only returns the collection for the default store?

What is not correct with my example?

  • : can i get the working code?
    – zus
    Commented Jan 23, 2018 at 6:20

4 Answers 4


Instead of store filter, try with root category filter.

$rootcatID = Mage::app()->getStore()->getRootCategoryId();

$productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('category_id', array('in' => $rootcatID))

  • 2
    As mentioned on a previous answer, calling load directly on a collection is not desirable.
    – philwinkle
    Commented Oct 14, 2013 at 17:32
  • 6
    Why this answer accepted as correct? Question is about category collection, not product mentioned here.
    – mageUz
    Commented Oct 14, 2013 at 17:45
  • 2
    @Marty: Did this answer really solve your questions? You might want to edit the question to make it clearer?
    – Alex
    Commented Oct 18, 2013 at 0:46

In Magento store has relationship with only root category and all categories belong to this root category are belong to particular store. To load store categories you should use store root category id, and you can load all categories of this root. See these:

    $rootId     = Mage::app()->getStore($storeId)->getRootCategoryId();
    $categories = Mage::getModel('catalog/category')
        ->addFieldToFilter('path', array('like'=> "1/$rootId/%"));

    echo $categories->count();
  • 2
    this should be accepted
    – Hashid
    Commented Nov 24, 2014 at 6:02
  • this works well but left me a question. What's the point of magento having setStore if it doesn't automatically filter collection by its root category ID for that current store? Commented Oct 12, 2017 at 3:26

In Magento 1.9

$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();

            $categories = Mage::getModel('catalog/category')
                ->addFieldToFilter('is_active', 1)
                ->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))

                foreach ($categories as $categorie)
                    $catid = $categorie->getId();                   
                    $catname = $categorie->getName();
                    $catp = $categorie->getParentId();
  • so what is causing the correct filter here? Is t the store specific rootCategoryId || is it ->setStoreId($storeId) in the collection?
    – snh_nl
    Commented Jan 27, 2017 at 19:26

Maybe this could help somebody, but with a little digging and testing i came up with the following:

$catCollection = Mage::getModel('catalog/category')->getCollection()
    ->setStoreId(9) //where 9 should be your store id
    ->addFieldToFilter('is_active', 1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.