0

How to access the root category url or in other words default url for all product listing in magento 2?

1 Answer 1

0

In Block

<?php

namespace Vendor\Module\Block;

use Magento\Framework\Registry;

class A
{
    public $registry;

    public function __construct(Registry $registry) 
    {
        $this->registry = $registry;
    }


    public function getCurrentlyCategoryPath()
    {
       $category = $this->registry->registry('current_category');
       return $category->getUrl();
    }
}
1
  • I was expecting it without any code. For example the category page url is domainname.com/men.html similarly I wants to access the default product listing on the category page even without creating any parent category. Is it possible or what is the best way to achieve it. Jul 12, 2019 at 11:21

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.