cancel
Showing results for 
Search instead for 
Did you mean: 

How to get store information in Magento?

How to get store information in Magento?

In Magento, how can I get active store information, like store name, line number, etc?

1 REPLY 1

Re: How to get store information in Magento?

Here are a few ways to get the active store information like name, code, id etc. in Magento:

1. Get the store manager and current store object:

php

$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();

2. Get store data from the store object:

php

$storeId = $currentStore->getId();
$storeCode = $currentStore->getCode();
$storeName = $currentStore->getName();

3. Alternatively use the store resolver model:

php

$storeResolver = $objectManager->get('\Magento\Store\Model\StoreResolver');
$currentStoreId = $storeResolver->getCurrentStoreId();
$currentStoreCode = $storeResolver->getCurrentStoreCode();

4. Or inject \Magento\Store\Model\StoreManagerInterface and get current store directly:

php

$this->storeManager->getStore()->getId();

So in summary, the store manager, store resolver, and current store object give you access to active store data like ID, code, name, website ID, store group, and more!