How can I get current Magento 2 store info from Block class programmatically. Like store name, store id, store code, store url, is store active, website id and store name
To get current Magento 2 store’s info programmatically, you need load “Magento\Store\Model\StoreManagerInterface” object first and then call “getStore()” method to retrive current store object. Here is the example.
objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’);
Get current store’s id
$storeManager->getStoreId();
Get current store’s code
$storeManager->getStoreCode();
Get current website ID
$storeManager->getWebsiteId();
Get current store’s name
$storeManager->getStoreName();
Get current store’s url
$storeManager->getStoreUrl();
Check current store is active or inactive
$storeManager->isStoreActive();
0 0 votes
Article Rating