1

I want to filter category by store id. Used the following code, but it is not working.

$collection = $this->categoryCollectionFactory->create();
        $collection->addAttributeToSelect('*')
        ->setStoreId(0);
0

Try below code. this is working for me.

$collection = $this->categoryCollectionFactory->create();
$collection->addAttributeToSelect('*');        
$collection->addStoreFilter($this->_storeManager->getStore($store_id));
0
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $categoryCollection = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');

    $categories = $categoryCollection->create();
    $categories->addAttributeToSelect('*');
    $categories->setStore('0'); /* set here your store id */

    foreach ($categories as $category) {
        echo $category->getName() . '<br />';
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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