Magento - Filter category resource collection by store_id

前端 未结 6 1448
谎友^
谎友^ 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:39

    In Magento 1.9

    $storeId=2;
        $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
    
                    $categories = Mage::getModel('catalog/category')
                        ->getCollection()
                        ->setStoreId($storeId)
                        ->addFieldToFilter('is_active', 1)
                        ->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
                        ->addAttributeToSelect('*');
    
                        foreach($categories as $categorie)
                        {
                            $catid=$cat->getId();                   
                            $catname=$categorie->getName();
                            $catp=catp$categorie->getParent_id();
    
                        }
    

提交回复
热议问题