Magento - Filter category resource collection by store_id

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

    I spent a lot of time.... this exaple work for me...

    $store = Mage::app()->getStore()->getId();
    $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
    
    $rootpath = Mage::getModel('catalog/category')
                        ->setStoreId($store)
                        ->load($rootCategoryId)
                        ->getPath();
    
    $categories = Mage::getModel('catalog/category')->setStoreId($store)
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter('path', array("like"=>$rootpath."/"."%")); 
    

    fix for multistore :)

    setStoreId - not work, can remove

提交回复
热议问题