Magento - Filter category resource collection by store_id

前端 未结 6 1422
谎友^
谎友^ 2021-01-03 18:54

I am trying to pull category that belongs to current store only but it doesn\'t seem to work. Can anyone see any issue in my code?

$categoryCollection = Mage         


        
6条回答
  •  走了就别回头了
    2021-01-03 19:46

    Neither setStoreId() nor addAttributeToFielter('store_id', $storeId) don't work because there's no store_id in the category tables. The code below works perfectly:

    $storeId = 21; // your store id
    $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
    $categories = Mage::getModel('catalog/category')->getCollection();
    $categories->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
    

提交回复
热议问题