2

is there any way we can get all category ids like its displayed in admin in Magento ver. 2.4.3 ?

I have tried

     **
     * Get Category
     */
    public function getCategory($categoryId) 
    {
        $category = $this->_categoryFactory->create();
        $category->load($categoryId)->setOrder('entity_id', 'ASC');
        return $category;
    }

but this did not work.

Thank you

1
  • any thoughts on this ?
    – user104369
    Commented Aug 28, 2022 at 8:50

1 Answer 1

0
 protected $categoryHelper;

    public function __construct(
        \Magento\Catalog\Helper\Category $categoryHelper,        

    ) {
        $this->categoryHelper = $categoryHelper;   
    }

    /**
     * Retrieve current store level 2 category
     *
     * @param bool|string $sorted (if true display collection sorted as name otherwise sorted as based on id asc)
     * @param bool $asCollection (if true display all category otherwise display second level category menu visible category for current store)
     * @param bool $toLoad
     */

    public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
    {
        $categorys = $this->categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
        foreach($categorys as $category){
        echo $category->getId()
    }
    }

  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.