I am using the below code to find store specific categories but here I am not getting the categories that are not included in the menu. How can I get those categories also?

    protected $_categoryHelper;
    public function __construct(
    \Magento\Catalog\Helper\Category $categoryHelper

    $this->_categoryHelper = $categoryHelper;

    public function getAllCurrentStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
    return $this->categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);

      in template

// get current store's categories
$categories = $block->getAllCurrentStoreCategories();
foreach ($categories as $category) {    
    echo $category->getName() . '<br />';

Can you please try this code.

protected $_storeManager;

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    $data = []
) {
    $this->_storeManager = $storeManager;

$objectManager = $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categories = $categoryFactory->create()                              
    ->setStore($this->_storeManager->getStore()); //categories from current store will be fetched

foreach ($categories as $category){

Happy Coding.

| improve this answer | |
  • Hi Mayur, Thanks for your respond, By using the above I am not getting store specific categories. the above code is returning all categories. – Payal Apr 13 at 11:35
  • It will help you to fetch current store all categories. – Mayur Sisodiya Apr 13 at 11:36
  • Already verified I am having 2 different stores and websites it is returning all categories. – Payal Apr 13 at 11:43

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.