How to get Current Store information – Magento 2

In magento 2 every store has some information like, Name, Id and its status. The main class which deals with store information is 



create an object of this class and get all its method related to store information.


namespace Mage\Knowledge\Block;

use Magento\Store\Model\StoreManagerInterface;

class Store extends \Magento\Framework\View\Element\Template


 private $storeManager;

 public function __construct(StoreManagerInterface $storeManager)


   $this->storeManager = $storeManager;




Now using the above variable you can get all store information e.g

$store= $this->_storeManager->getStore();


  • $store->getId()
    it will return store id. 0 is admin store.
  • $store->getWebsiteId()
    get the current store website id.
  • $store->getCode()
    get the code defined for current store.
  • $store->getName()
    get the name of current store.
  • $store->getCurrentUrl(true)
    get the current store url.
  • $store->isActive()
    check the value 0 or 1 if store is active or not.

So what we have learned today that using about class and its object we can get all store information and use it where we want to.

About Ejaz Alam

A Software Engineer who Believes in a simple lifestyle and follow a simple logic to make himself better than yesterday. :)

View all posts by Ejaz Alam →

Leave a Reply

Your email address will not be published. Required fields are marked *