I want to give one link to browse the root category. root category should load all products and with out tool bar.i found some articles for m1. any one have idea?

  • You should accept answer to help other developers to find there solutions Commented Nov 25, 2017 at 6:56

1 Answer 1


Inject Magento\Catalog\Model\CategoryFactory class to get product collection.

protected $categoryFactory;

public function __construct(
    \Magento\Catalog\Model\CategoryFactory $categoryFactory
) {
    $this->categoryFactory = $categoryFactory;

public function getCategoryProduct($categoryId)
    $category = $this->categoryFactory->create()->load($categoryId);

    return $category;

Now call getCategoryProduct() in phtml file,

$categoryId = 10;
$getProudctcollection = $block->getCategoryProduct($categoryId);

foreach ($getProudctcollection as $product) {
    echo $product->getName(); //Get Product Name
    echo $product->getProductUrl(); //Get Product URL

Your Answer

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

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