Magento 2 get Store Details– It is very simple to get the store details in Magento 2. There are two ways to get the store information in Magento 2 – 1. Using dependency Injection, 2. Using Object Manager. Here in this post we are going to get the – store id, store code, store name, store website, store url etc.
Magento 2 get Store Details | Id, Name ,Code
Let us get the following details from current store in Magento2-
Get Information From Current Store
We need following details about current store while working with magento.
- Store Name
- Store Id
- Store Code
- Store Website Id
- Store Url
We can get the above information using object manager. Here is simple Example.
Get Store Information Example:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface'); $storeName = storeManager->getStore()->getName(); $storeId = $storeManager->getStore()->getStoreId(); $websiteId = $storeManager->getStore()->getWebsiteId(); $storeCode = $storeManager->getStore()->getCode(); $storeUrl = $storeManager->getStore()->getStoreUrl(); |
So on the same way you can get other details of the current store.